Multiple fonts/colors of characters in JTextArea

How can I have multi color / font characters in a JTextArea? If it can't be done in JTextArea, then how to do it in Swing?

Use a JTextPane or a JEditorPane.

Similar Messages

  • Multiple font colors

    what's up
    does anybody know how to display font in multiple colors in a Jtextarea or another text component every time i change the font color in my jtextarea it changes for all the words i want it to change for only the next words that i type.
    thanks

    the following sample might be useful to u. i am not sure whether this works for textarea.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class test extends JApplet
         private JTextPane pane;
         private JButton colors;
         private JToolBar tb;
         public void init()
              pane = new JTextPane();
              tb = new JToolBar(JToolBar.HORIZONTAL);
              colors=new JButton("Colors");
              colors.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        Color newColor = javax.swing.JColorChooser.showDialog(null,"Choose Text Color",Color.cyan);     
                                  if(newColor!=null){
                                            MutableAttributeSet attr = new SimpleAttributeSet();
                                            StyleConstants.setForeground(attr,newColor);
                                            pane.setCharacterAttributes(attr,false);
              tb.add(colors);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(tb,"North");
              getContentPane().add(pane,"Center");
    //<applet code=test.class width=300 height=300></applet>
    for more information follow this link.
    http://manning.spindoczine.com/sbe/files/uts2/Chapter20html/Chapter20.htm
    cheers
    sri

  • Jtable cell having multiple font colors

    Is it possible to have text in a cell with multiple colors (e.g. using html)?
    -Jim

    Should be possible:
    http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
    I was able to do different colors by adding HTML to one of my table cell data items:
    <html><center><b>Enable</b> <font color=#ff00dd>middle button</font>

  • Multiple text colors in a JTextArea

    i created a JTextArea in a frame --- // JTextArea ta = new JTextArea();
    and wrote some words onto it with codes like: ta.append("abcd");
    ta.append("efg");
    how to make the color of the words "abcd" different from "efg"?

    JTextArea doesn't support multiple fonts and colours. Have a look at JTextPane or JEditorPane which allow more flexibility in formatting your text. JEditorPane also supports HTML.

  • Certain special characters do not display correctly in Firefox ( font COLOR="#1f1a17" FACE="Symbol" SIZE="3" ¬ /font ). Is there a fix?

    Certain special characters which display correctly in Explorer do not display correctly in Firefox. Example: <font COLOR="#1f1a17" FACE="Symbol" SIZE="3">¬</font>
    Is there a fix?

    The symbol font usually doesn't work in Firefox, a website needs to use an Unicode replacement or an HTML entity to specify such a character.
    See:
    *[https://developer.mozilla.org/en/Mozilla_Web_Developer_FAQ#Why_aren.e2.80.99t_symbol.2fdingbat_fonts_working.3f Why aren’t symbol/dingbat fonts working? - MDC FAQ]
    *http://en.wikipedia.org/wiki/Unicode_symbols
    *http://en.wikibooks.org/wiki/Unicode/Character_reference/2000-2FFF

  • Changing Font Color in JTextArea

    This question may sound a bit ridiculous to more experienced programmers (I am new to this programming thing)
    but I hope you will help me anyway.
    My problem: How can I change the color of the font
    within a JTextArea or other Swing text objects??
    I could not find any method (like setFontColor) or font
    constructor like Font(Color c).
    Is it maybe possible to change the color with the UIManager ('look and feel')??
    Thank you.

    setForeground(color)

  • Change the font color of a text field in a table by key-combination

    I want to change the font color of a text field in a table (single cell only) on pressing a key combination. Does anybody know how to do this.
    I have a lot of data in a table. During an evaluation of the data in a meeting I want to change the color of the text depending on the result of the meeting. (for example: High risk = CTRL+R makes the text red).
    I know how to change the color using a button, but I do not want to add a button after each cell. For this reason I would like to do it on a key combination that alway refers to the active cell.
    Many thanks for your help in advance.
    Marcel

    Hi,
    I don't think you can use the ctrl key like that as those shortcuts will be intercepted by Reader (ctrl-R toggles the ruler display on / off).  You also might have trouble updating the color while you still have focus on it.  You can use the shift key in a similar way, so if you only have lower case characters in the text fields then you can do something like;
    if (xfa.event.shift)
        switch (xfa.event.change)
            case "R":
                this.fontColor = "255,0,0";
                break;
            case "O":
                this.fontColor = "255,102,0";
                break;
            case "G":
                this.fontColor = "0,255,0";
                break;
        xfa.event.change = ""; // ignore character
    If you need uppercase characters maybe you can have one button to set "review mode" and test that on the if (xfa.event.shift) line.  But again it wont take effect until you have tabbed out of the field.
    Regards
    Bruce

  • How do I embed multiple font outlines in dynamic text field

    Can anyone tell me how I can embed multiple font outlines in
    Flash MX so I can get smooth text in a dynamic
    text frame? I want to use Regular, bold and italic in various
    parts of the text.
    I was using the Character button in the properties manager
    and tried to include all Characters. That does not work.
    In the Properties manager I can choose Bold and/or Italic.
    But it becomes a universal setting that overrides my HTML tags in
    my external txt file that I am importing. I dont want all my text
    to be bold.
    If I dont select them in the properties, however, Flash will
    not embed the font that it needs.
    Is there a different way to embed fonts other than under the
    Character Tab?
    I tried to import fonts to the library, but can not select
    them.
    Your help would really be appreciated.
    Sincerely,
    ggaarde

    ggaarde wrote:
    > Thanks Urami
    > Tried your method and it does not work for me.
    > I put 3 dynamic text fields in the first frame of the
    movie. Set them up to
    > where one is regular, one is bold and one is italic
    Helvetica.
    Weird, it works for me on first go, always had in fact :)
    Show you an example, try to compare to your file see if you
    missed anything accidentally.
    http://flashfugitive.com/stuff/font/text.swf
    text file
    http://flashfugitive.com/stuff/font/text.txt
    fla
    http://flashfugitive.com/stuff/font/text.fla
    Best Regards
    Urami
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • Multiple Fonts in a javax.swing.JTextPane

    I am trying to use multiple fonts in a JTextPane, but can only find ways of changing the font family used. Can anyone give me any pointers on how to do this, or a document somewhere that explains, either way with out going into the javax.swing.text.html, javax.swing.text.html.parser or java.awt.font packages.
    Any information that can be provided would be appreciated.
    Thanks,
    Nathan

    Just use SimpleAttributeSet like :
    SimpleAttributeSet defaultSet = new SimpleAttributeSet();
            StyleConstants.setForeground( defaultSet, Color.BLACK );
            StyleConstants.setFontFamily( defaultSet, "Verdana" );
            StyleConstants.setFontSize( defaultSet, 14 );
            SimpleAttributeSet navigationSet = new SimpleAttributeSet();
            StyleConstants.setForeground( navigationSet, new Color(00, 99, 00) );
            StyleConstants.setBold( navigationSet, true );
            StyleConstants.setFontFamily( navigationSet, "Verdana" );
            StyleConstants.setFontSize( navigationSet, 11 );
    // just defiine endPoints what ever you want
    ((DefaultStyledDocument)textPane.getDocument()).setCharacterAttributes(0, endPoint1, defaultSet , true)
    ((DefaultStyledDocument)textPane.getDocument()).setCharacterAttributes(0, endPoint2, navigation , true)

  • Changing font color in a report using SQL query for APEX 5.0

    Hello,
    I am testing APEX 5.0 in my testing environment to see if I can migrate my internal apps from 4.2 to 5.0.
    How can I change the font color in a field based in the SQL query? I know how to do it in 4.2 but I can't find the same in 5.0.
    Thanks,

    Well, I used to put the html tags in the select as text getting the color value depending a CASE , then I had to change the Display attribute for the column in the report as "Display as text (espace special characters...)".
    I found an old post here: https://tylermuth.wordpress.com/2007/12/01/conditional-column-formatting-in-apex/ and  this method still worked for me in APEX 5.0
    Thanks anyways

  • How to retrive the font color, style and size of the copied text from html

    I have requirement, where I need to retrive font size and style of the copied text from html page. Here copied text I mean, the text we select and copy using either windows copy command or using Ctrl+C.
    Please help me to get the solution for this req.
    Thanks in advance,
    Amodnk.

    You can also try this, especially if you've got the Text Inspector and the Color Picker open already.
    Select the text to be colored (note that if the text is already multiple different colors the swatch under Color & Alignment section of the Text Inspector still only shows one out of the several)
    Find the color you want in the Color Picker
    Click and drag from the Color Picker into the swatch under Color & Alignment in the Text Inspector
    That will also change all the selected text to the chosen color.
    Also, regarding web safe colors, that SHOULD come as a part of the Color Picker. With the Color Picker open, select the third icon at the top (If you mouse over it, it should indicate Color Palettes. Click the popup menu button and you should see Web Safe Colors as one of the choices. With this and the Text Inspector open, you can drag and drop your way to identical colors in no time!
    That same drag and drop trick works for text on the slide as well. If you just created a bit of text and you want to apply a color, scroll until you find the color you want, then drag and drop over to the text (it will highlight in blue showing you what you're about to color).

  • Change the font of part of a JTextArea

    Hi,
    I would like to know if it is possible to change the font of part of a JTextArea, because the setFont method changes the entire text.

    As per the [Sun text component tutorial|http://java.sun.com/docs/books/tutorial/uiswing/components/text.html]:
    JTextArea can display multiple lines of editable text. Although a text area can display text in any font, all of the text is in the same font. Use a text area to allow the user to enter unformatted text of any length or to display unformatted help information.
    To achieve your goal, you may need to look into using another text component such as a JEditorPane or JTextPane. I recommend that you have a look at the tutorial linked above.

  • Font change to Courier in JTextArea

    Is it possible to change the font to Courier in a JTextArea so that the spacing of the characters is even for easy output? If it is possible any help would be awsome!

    Yes it is :)
    Use something like:
    javax.swing.JTextField tf = new javax.swing.JTextField();
    tf.setFont(new Font("courier"); This should do the trick, but double check, I'm not a GUI programmer ;-)

  • My Excel with PowerPivots acts weird, it hangs when i try to change font color

    Hi 
    I am facing a weird issue using PowerPivot in my workbook, there is a worksheet named Charts in my workbook and all the charts i am using resides in that worksheet. Whenever i try to change the font color in that sheet, my excel's color palette goes blur
    and then everything just freezes and turns black. This problem is happening only with Charts worksheet, when i try to change the color in other sheets, it works just, the problem is only with Charts sheet. File
    size is 16 MB, there are just 10 pivot tables with some calculations and some calculated fields. There are no add-ins other than PowerPivot. 
    Thanks,
    Shanker

    Hi,
    In regarding of the issue, please provide us more information to assist you better.
    Do you receive any error message?
    Which Excel version are you using?  Excel 2013 or other?
    Which workbook format are you using? XLS or XLSX?
    Are you performing any specific task?
    According to your description, this issue seems only occur with the special worksheet "Charts".
    Firstly, I recommend we copy all of the content to a new/blank Excel file to test.
    If it works fine, this issue might be caused by the "Charts" workbook itself. We'd better check the "Charts" workbook. Or re-build the file with a new workbook.
    If it still makes Excel hang with a new file, this issue might due to the content. Please check the content first.
    Secondly, we could follow below KB to troubleshoot this issue:
    https://support2.microsoft.com/kb/2758592/en-us?wa=wsignin1.0
    Thirdly, if the issue still exists, we may try to collect the Event log and App crash dump file to do advanced troubleshooting.
    Event log:
    http://windows.microsoft.com/en-US/windows7/Open-Event-Viewer
    App crash dump file:
    First enable app crash dump collection by copying following words into notepad, saving it as dump.reg and importing
    it:
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\localdumps\EXCEL.EXE]
    "DumpFolder"=hex(2):63,00,3a,00,5c,00,63,00,72,00,61,00,73,00,68,00,64,00,75,\
      00,6d,00,70,00,73,00,00,00
    "DumpCount"=dword:00000010
    "DumpType"=dword:00000001
    "CustomDumpFlags"=dword:00000000
    Then, open Excel
    to repro the issue. If crash issue appeared, please find the crashdump file under c:\.
    To further help you, please upload this file into Skydrive and shared the link here.
    Also, you can try to analyze dump by yourself if you would like to:
    How to analyze app crash dump file:
    http://blogs.technet.com/b/askperf/archive/2007/05/29/basic-debugging-of-an-application-crash.aspx
    Hope it's helpful.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Copying from Oracle SQL Developer to Microsoft Word doesn't retain formatting (Font,colors etc)

    Copying from Oracle SQL Developer Worksheet doesn't retain formatting (font,color etc...)in Microsoft Word but copying from other programs such as
    visual studio, chrome browser etc works fine. This doesn't work even after changed the setting to Keep Source formatting of Options-> Copy and Paste Settings

    Hi,
    I notice that you have cross posted in Answers forum and Oracle forum. Have you tried Mr. Peter's suggestion?
    Then, I recommend we check the Word settings:
    1. Go to: Options > Advanced > Cut, Copy and Paste
    2.  Make sure that Use smart cut and paste is ticked. 
    3. Click the Settings button next to this option
    4. Make sure that Smart Style
    Behavior is checked.
    If the issue still exists, please upload a sample through One Drive, I want to test.
    Regards,
    George Zhao
    TechNet Community Support

Maybe you are looking for

  • Missing Information in Elements 12

    In prior versions of Elements, when a file was opened in the organizer, at the bottom of the screen it showed all albums in which the file could be found.  Is that feature not available in Elements 12?

  • Getting started with smartZynq module (soc-e)

    Hi everybody, for a project in my compagny I have to discover and use a ZynQ-7000 based board called smartZynQ (soc-e) here are some information about this board soc-e : http://soc-e.com/smart-zynq-module/ xilinx : http://www.xilinx.com/products/boar

  • Applets in Applet Tutorial Fail

    I am trying to work through the tutorial on applets. Every page in this tutorial with an applet in it fails to load the applet. For example, when I load http://java.sun.com/docs/books/tutorial/deployment/applet/browser.html I get the following error:

  • When linking up or down...

    when using the ../ means going up a level ../../ means going up two levels...is there a corresponding designation if you want to go down a level ? and what is it?

  • When do surfaces get uploaded to VRAM / removed from VRAM?

    Hello! I'm aware of the differences of cacheAsBitmap and cacheAsBitmapMatrix and when to use them. However, can someone answer me the following questions? 1. If I set cacheAsBitmap=true - when does the DisplayObject get rendered into a bitmap? at the