Font in a text area

I am creating a word processor which allows for font changes. it works to change the font, but it will change previously entered font in addition. i do not want text that has already been entered to be changed by new settings. how can i accomplish this?
for reference, this is an example of how i change the font:
oldFont = textArea.getFont();
textArea.setFont(new font(oldFont.getFontName(),Font.ITALIC,oldFont.getSize()));Thanks.

Ok, so I implemented a text Pane setup. Though, it still does the same thing. Any time an option is modified, all of the text will change.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
public class wordTemp extends JFrame {
     private final int sizeValues[] = { 8, 9, 10, 11, 12, 14, 16, 18, 20, 25, 36, 48, 72};
     private final String fontNames[] = { "Serif", "Monospaced", "SansSerif" };
    private JRadioButtonMenuItem sizeItems[], fonts[];
    private JToggleButton boldButton, italicButton;
    private JTextPane textPane;
    private ButtonGroup fontGroup, sizeGroup;
        private Font oldFont;
        private StyleContext context = new StyleContext();
     private StyledDocument document = new DefaultStyledDocument(context);
     private Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
    // set up GUI
    public wordTemp()
         super( "SimpWoPro - Simple Word Processor" );    
        // set up File menu and its menu items
        JMenu fileMenu = new JMenu( "File" );
        fileMenu.setMnemonic( 'F' );        
        // set up About... menu item
        JMenuItem aboutItem = new JMenuItem( "About SimpWoPro..." );
        aboutItem.setMnemonic( 'A' );                    
        fileMenu.add( aboutItem );                       
          aboutItem.addActionListener(
             new ActionListener() {  // anonymous inner class
                  // display message dialog when user selects About...
                  public void actionPerformed( ActionEvent event )
                              JOptionPane.showMessageDialog( wordTemp.this,
                           "This is a simple word processor \n     developed to show menus and ways \n of altering fonts in a \n text area.",
                           "About", JOptionPane.PLAIN_MESSAGE );
                 }  // end anonymous inner class
            ); // end call to addActionListener
            // set up Exit menu item
            JMenuItem exitItem = new JMenuItem( "Exit" );
            exitItem.setMnemonic( 'x' );                
            fileMenu.add( exitItem );                   
            exitItem.addActionListener(
            new ActionListener() {  // anonymous inner class
               // terminate application when user clicks exitItem
               public void actionPerformed( ActionEvent event )
                  System.exit( 0 );
            }  // end anonymous inner class
            ); // end call to addActionListener
            // create menu bar and attach it to MenuTest window
            JMenuBar bar = new JMenuBar();                    
            setJMenuBar( bar );                               
            bar.add( fileMenu );                              
            // create Format menu, its submenus and menu items
            JMenu formatMenu = new JMenu( "Font Type" ); 
            formatMenu.setMnemonic( 'r' );          
            // create size submenu
          String sizes[] = { "8", "9", "10", "11", "12", "14", "16", "18", "20", "25", "36", "48", "72"};
          JMenu sizeMenu = new JMenu( "Font Size" );
            sizeMenu.setMnemonic( 'S' );         
        sizeItems = new JRadioButtonMenuItem[ sizes.length ];
          sizeGroup = new ButtonGroup();                       
            ItemHandler itemHandler = new ItemHandler();
        // create size radio button menu items
        for ( int count = 0; count < sizes.length; count++ ) {
                 sizeItems[ count ] = new JRadioButtonMenuItem( sizes[ count ] );
            sizeMenu.add( sizeItems[ count ] );         
                sizeGroup.add( sizeItems[ count ] );        
            sizeItems[ count ].addActionListener( itemHandler );
        // select first size menu item
        sizeItems[ 0 ].setSelected( true ); 
        // create Font submenu
            JMenu fontMenu = new JMenu( "Font" );
            fontMenu.setMnemonic( 'n' );        
            fonts = new JRadioButtonMenuItem[ fontNames.length ];
            fontGroup = new ButtonGroup();                      
           // create Font radio button menu items
            for ( int count = 0; count < fonts.length; count++ ) {
             fonts[ count ] = new JRadioButtonMenuItem( fontNames[ count ] );
             fontMenu.add( fonts[ count ] );                                
             fontGroup.add( fonts[ count ] );                               
               fonts[ count ].addActionListener( itemHandler );
        // select first Font menu item
            fonts[ 0 ].setSelected( true );
            // Create the bold button.
            boldButton = new JToggleButton( "Bold" );
            boldButton.addItemListener(
               new ItemListener() {  // anonymous inner class
                   public void itemStateChanged(ItemEvent e) {
                       if (e.getStateChange() == ItemEvent.SELECTED) {
                                   StyleConstants.setBold(style, true);
                       else{
                                 StyleConstants.setBold(style, false);
               } // end anonymous inner class
            // Create the italic button.
            italicButton = new JToggleButton( "Italic" );
            italicButton.addItemListener(
               new ItemListener() {  // anonymous inner class
                   public void itemStateChanged(ItemEvent e) {
                       if (e.getStateChange() == ItemEvent.SELECTED) {
                                   StyleConstants.setItalic(style, true);
                       else{
                                 StyleConstants.setItalic(style, false);
               } // end anonymous inner class
          // add Format menu to menu bar
            bar.add( fontMenu ); 
            bar.add( sizeMenu );
            bar.add( boldButton );
            bar.add( italicButton );
               textPane = new JTextPane(document);
            JScrollPane scrollPane = new JScrollPane(textPane);
            getContentPane().add( scrollPane );
           setSize( 500, 200 );
            setVisible( true );
   } // end constructor
     public static void main( String args[] )
         wordTemp application = new wordTemp();
            application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        // inner class to handle action events from menu items
    private class ItemHandler implements ActionListener {
       // process size and font selections
       public void actionPerformed( ActionEvent event )
        // process size selection
                for ( int count = 0; count < sizeItems.length; count++ ){
                    if ( event.getSource() == sizeItems[ count ] ) {
                         StyleConstants.setFontSize(style, sizeValues[count] );
             // process font selection
             for ( int count = 0; count < fonts.length; count++ ){
                 if ( event.getSource() == fonts[ count ] ) {
                         StyleConstants.setFontFamily(style, fontNames[count] );
         } // end method actionPerformed
        } // end class ItemHandler
}How could I change this so that old text is not changed?
Thanks.

Similar Messages

  • Changing font in a text area?

    how do you change the font in a text area
    i thought it might have been navi.setFont(Font.Verdana);
    but no ...

    Right idea, but it's off. Try this:
    navi.setFont(new Font("Verdana", Font.PLAIN, 12));

  • How to change the Font in the Text Area

    Hi,
    My Apex application is set up in Arial.
    But when I use a Text Area the font changes to Times Roman.
    How to solve that?
    Thanks in advance, Marti

    hi,
    try writing:
    style="font-family:Arial;"
    in the page element attribute called "HTML Form Element Attributes"
    bye,
    Flavio
    http://oraclequirks.blogspot.com/search/label/Apex

  • Font size in text area

    I have columns defined as readonly text area in a report. I have created a template so that all the reports fields have a font size of 9px. Everything sets to 9px except the fields defined as text areas. can the font size be changed on text area in reports?

    Hi Brian,
    you can add class="myClass"
    to the HTML Form Element Attributes region of the page item.
    This should allow you to apply the appropriate font-size etc.
    Alternatively, you could apply them directly to the input tag in your style sheet.
    input {font-size:32;}
    Regards
    Michael

  • Italic and bold fonts for Hoefler Text are no longer available to MS Word

    Apple provides regular, italic, black, and black italic styles for the Hoefler Text font. I've used them before but since I installed Snow Leopard, I cannot creat italic or bold (black) in MS Word. When I make text italic or bold (black), the characters disappear--the sentence shortens as if I had deleted the phrase, but if I change it back to regular, it reappears.
    Font Book shows that I have all of these styles of Hoefler Text in the Library. I tried disabling and then enabling, but that didn't work. Has anyone else encountered this problem? If so, have you discovered a solution? Thank you.

    Thanks for the file. It obviously helped, but I am not sure how. I probably should have taken careful notes about what I did by way of disabling and removing the .ttf fonts and then dragging in the .dfont variety. At one stage when I brought up a Hoefler document in Word, the regular Hoefler text had disappeared. I panicked and removed the .dfont version. Later, after trying something else, the text came back but (judging by the numerals) it was not Hoefler. To make a long story short, all styles of Hoefler (including italic and black) are now working. There are no duplicate font files—I used Remove Duplicates—but I have no Hoefler file in either of the two Fonts folders, even though I can see Hoefler Text in Font Book! To be safe, I used Font Book to export the Hoefler Text to a back-up folder, and the version it exported is the .ttf version. In Get Info I confirmed that it’s the 6.1d7e1 variety. I restarted the computer twice, and determined that this situation is stable. Go figure.
    In any event, you set me on the right road. Hoefler Text is now working as it should. I appreciate your help.

  • I created a pdf form from a Word doc with 9 pt aerial font formatting; the text on the pdf form is aerial 9 pt, but the fields are formatted in courier 12 pt - How do I reformat the font in the fields??

    I created a pdf form from a Word doc with 9 pt aerial font formatting; the text on the pdf form is aerial 9 pt, but the fields are formatted in courier 12 pt - How do I reformat the font in the fields??

    You can set up a temporary button (or link, bookmark, etc.) and add the following JavaScript action:
    // Mouse Up script for a temporary button (or bookmark, etc.)
    // Change the font and font size for all text fields in this document
    for (var i = 0; i < numFields; i += 1) {
        var f = getField(getNthFieldName(i));
        if (f.type === "text") {
            f.textFont = font.Helv;
            f.textSize = 9;
    It also sets the font size, but you can remove that line if you don't need to do that.

  • Different  font colors in the same text area.

    i need to have a text area where i can setText with different colors.
    eg red if an error message, rest to be black.
    the only way to set text color i know is using setforegound color which will do the only documents, but i need to set font color per string.
    how?

    JTextPane
    StyledDocument
    MutableAttributeSet
    db

  • Photoshop CC icons and text are too small: how to adjust so they're readable? [was: Joanne]

    I have just downloaded Creative Cloud on a new computer.  The new photoshop icons and text are too small for me to see or work with.  I cannot seem to adjust this so its "useable"

    Hey Bob,
    Ive put feature requests for this in before and I know many others have as well. Is there any way to see if Adobe is actually working on this? I dont really consider this a feature request, it should be standard with the software. A feature request would be something like creative cloud libraries, not the ability to make font sizes and icons bigger.

  • HT4976 Some of emojis are not showing correctly in web view text are.

    When I input emojis in webview's text area, some are not showing as a emojis, they are showing as a symbole e.x. ☺ (WHITE SMILING FACE),✌(VICTORY HAND) e.t.c., these are not the correct emoji as they are showing in apple device keyboard.
    Can you please sugges me what should i do ?

    Is Webview an app? If so, it may not support the Emoji font. Or, if you're talking about typing in a web page, the same maybe true. The iPhone Emoji font frequently shows up as garbage characters on other phones. It sound as if it's being converted to the Symbol font in whatever your trying to use it. Avoid use of the Emoji font unless you are communicating with other iOS devices.

  • Tab and next line characters in text area

    Hi,
    I have an issue with the textarea. The page is inserting /t and /n in the text I type in and everytime I save.
    I defined a text area like following in my jsp:
                   <textarea class="textarea_value" name="explanation" rows="5" cols="100">
                   <bean:write name="tiptrackerEditForm" property="explanation"/>
                   </textarea>
    css:
         .textarea_value {
              font-weight: normal;
              font-size: 12px;
         text-align: left;
         wrap: soft;
    When I type in a word in textarea, it saves without any /t or /n. But when retreive the data and load it into the form again, the page shows with an inserted tab (the word is moved to the right after inserting a tab). Everytime I save, it inserts a tab and /n characters. I know for the fact that the database or the form is doing this. It's in the jsp.

    Put the whole <textarea> element in a single HTML line without newlines and spaces.
    Thus, so:<textarea class="textarea_value" name="explanation" rows="5" cols="100"><bean:write name="tiptrackerEditForm" property="explanation"/></textarea>

  • Which event dispatched after text selection done on spark text area in Apple iPad using Adobe Flex 4

    I need to know which event triggered after text selection done in Apple iPad. This way i have done in desktop air app code (mouse events)
    protected function txtEditor_mouseUpHandler(event:MouseEvent):void
                if(txtEditor.selectionAnchorPosition != txtEditor.selectionActivePosition){
                    showNoteToolBar(event);
                    txtEditor.focusEnabled = true;
                    txtEditor.setFocus();
    But in Apple iPad how to achieve through "Touch Event" ? And also i need how to hide all context menu on Spaek TextArea?. Why Touch.End event is not fired after place cursor on text area ?
    Please help me !

    Ok, so I finally got it working but this is not ideal at all. Adobe really needs to give us some direction on how to properly deal with font embedding and TLF now that the release build breaks all functionality with loading runtime fonts and TLF.
    Problem:
    I am embedding collections of fonts (faces) into single family classes. Each individual face is registered with Font.registerFont(). I need to do this because I have to have mixed fonts within text flows - at least according to Alex H's recent blog post.
    Fonts do not display in TLF without doing the following:
    1. GlobalSettings.resolveFontLookupFunction = null;
    2. editor.textFlow.flowComposer.swfContext = ISWFContext(this.getFontContext("AnyFamilyNameFromAnyFontEmbedded", false, false, FontLookup.EMBEDDED_CFF));
    3. Instead of #2, use editor.textFlow.invalidateAllFormats();
    Either #2 or #3 need to be performed. If I have a spark richEditableText control in MXML with defined familes from the loaded fonts. I even tried placing the control into a separate state so it wasn't created until after the fonts were loaded... I still needed to invalidate the formats or set the context.
    The "AnyFamilyNameFromAnyFontEmbedded" does not need to be all of the embedded family names. It only needs to be one of them. Once one is used, all embedded fonts work. Also, I have to use the internal namespace to even get access to getFontContext, another oddity that, in my humble opinion, should never be necessary to create mixed style TLF content.
    My questions are then:
    1. Why am I required to use ISWFContext if I am using Font.registerFont()?
    2. Why is GlobalSettings.resolveFontLookupFunction = null; also required for this to work?
    3. What is the recommended workflow to embed fonts from multiple SWF files into the release build and have it work without having to jump through all these hoops?

  • Font size of text too big on a mobile... why ?

    Hello, I use Muse CC 2014.
    I have the following problem:
    When I create a wide text area, and I write a few lines of text, when I look at the result on a mobile device (with Chrome for example, on Samsung Galaxy S4), in landscape mode all goes well, but in portrait mode, the text size becomes BIGGER !
    Therefore not possible to create a correct layout ...
    How to make the text size remains the same in portrait or landscape mode on a mobile device?
    Thank you very much
    Robin Weber

    znico,
    I am also having this same problem and I have a thread on it here [Font size larger than it should be in mobile version]. It also happens on my S4 on Chrome. It has been an ongoing issue on the sites I design where I'll put the text box inside of a colored box for instance and in other devices the text fits inside the box but in Chrome/S4 the text extends beyond the box. I tried viewing it in Firefox for Android and the text seems to render as it should. I'm guessing it has something to do with the way the S4 or Chrome is rendering the text. I have not had the time to check but I'm also wondering if it has anything to do with fonts from TypeKit as opposed to web safe fonts. What font type are you using in your design?

  • How to change the font size of text and case in smartforms

    hi,
       could any one explain how to change the font size of text in smartforms. ex. previously i had taken P4 left aligned and C6 but now i want to decrease the font without making it bold. pl......... guide me
       secondly the value which are coming from tables are upper case but i need lower case. pl. guide
    thanking u

    check out the smart styles...create a font of ur size n use.
    Define the paragraphs & character formats using SMARTSTYLES & use them in your smartform.
    You have to give the smartstyle name in the Form attributes-->Output options for the formats to be used in your smartform.
    You can define font size in Smartform Style.
    Smartform Styles > Charcterformat> Font --> size.
    to load the font to SAP server chk this
    Re: Adding a new font for SAPscript/SMARTFORM output
    Regards
    Vasu

  • How to change the color of the text in the Text Field or in the text area??

    HI all,
    i think its a very simple problem, still, can anyone tell me how i can change the color of the text and also its font, before i display it in either a textfield or a text area.
    bharath

    Just Use:
    JTextField.setForeground(Color.RED);
    so SIMPLE na!
    Balakumar .M
    http://i5bala.blogspot.com
    --

  • Hindi language in text area

    Hey Experts,
    I have a module where I have to display translation for
    Arabic,Spanish,Hindi in text area where user
    inputs text in English Language. This translation is done by
    the Google Translation API.
    I have succeeded in getting translation for Arabic and
    Spanish which is displayed fine in the Text Area.
    But for Hindi, its displaying boxes.
    How do I go about for this issue?
    The next thing what I did is
    I applied Hindi font style to text box when Hindi language is
    selected but still no success :(

    Hi there Linda
    I'm not sure where you are looking to say that your "project
    global settings" are English.
    Have you looked here? Click File > Record/Create > New
    Project
    When you reach the recording dialog (with the teal colored
    frame and the check boxes), click the Advanced button.
    See image linked below:
    Click here to see the
    image
    Cheers... Rick

Maybe you are looking for

  • Can not add videos to library

    Hi, i am having trouble adding vidoes to the itunes library. i have added 9 with no dramas, all play perfect on the iPod, but i can no longer add any more. i click on add files, the top of itunes quicky flashes teh tranfer bar, then nothing?? i have

  • Sort-by-type for column view in open/save dialog boxes?

    Hello all, I've done a fairly good search both on Google and in these forums and can't seem to find this question addressed. When I go to open or save something (in Preview, for example) I prefer to use Column View in the dialog box, since it is easy

  • No wi-fi on ipod touch

    I have had my ipod touch for about 7 months now and until recently I have had no problems with it. For some reason it says no wi-fi. I have no problem with the internet connection on other devices in my house and the ipod has no internet connection w

  • Use Ipad 2 or 3 or iphone as WIRELESS external monitor for DSRL Cannon?

    Hey you'll, I am wondering if i can use my ipad 2 or 3 or iphone 3 as a wireless external monitor for my DSLR Cannon t2i Rebel. there has to be an app by now, hope to hear from someone soon and thanks for your help!

  • Can I send the zoomed portion of a signal from data view to the next step

    I get a zoom window on Data View when I select it.  Can I send the zoomed portion to the next step or use it in any way?  If I Create VI with this,  will the zoomed portion show up in the VI?   Will a graph of any kind show up in the VI?