Results 1 to 12 of 12
Like Tree2Likes
  • 1 Post By JosAH
  • 1 Post By JosAH

Thread: JTextArea

  1. #1
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default JTextArea

    In my Word Project i am using JTextArea instead of JTextPane and i want to use JColorChooser to Color the Letters on the JTextArea.. but i search on the web but all say that this is not going to happen with JTextArea..

    There is anyway to avoid this problem??? or i should edit my entire project and change the JTextArea with JTextField?!?!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTextArea

    Quote Originally Posted by ShadowWalker View Post
    In my Word Project i am using JTextArea instead of JTextPane and i want to use JColorChooser to Color the Letters on the JTextArea.. but i search on the web but all say that this is not going to happen with JTextArea..

    There is anyway to avoid this problem??? or i should edit my entire project and change the JTextArea with JTextField?!?!
    JTextAreas and JTextFields are too simple to do that: the foreground color for all characters has to be the same (the same counts for the background color); you have to use another JTextComponent for the purpose (read the API documentation for the other extension classes of the JTextComponent class.

    kind regards,

    Jos
    ShadowWalker likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: JTextArea

    Oh Sh**t :P xD i had almost done :P ... i should check it :P thx for the fast reply!!

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: JTextArea

    No that is not quite true. You can change the Font in a JTextArea and you can change the color using the setForeground() method. But you can't format individual words like in a JTextPane.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: JTextArea

    yeah i know about setForeground() but i would like something more advance like :
    You mark the Word you want to color and then you choose a color and you color the marked word...
    so i have to change in JTextPane...

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTextArea

    Maybe a simple HighLighter can help you out (read the API documentation); it's not as powerful as, say, html tags for the other JTextComponent, but you can fiddle a bit with them. That site where you got the JColorChooser from has some fine examples for the use of a HighLighter.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: JTextArea

    yeah HighLighter will do something like this : JTextArea-p95cv.png
    and that's not what i want.. i will do what you say.. i will change the JTextArea with JTextPane ;)

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTextArea

    Yep, you can feed ordinary html tags to a JTextPane; the html accepted is somewhere beween versions 3.2 and 4.0 with a couple of restrictions (e.g. it can only handle one level of subscript and superscript which was a real showstopper for an old project of mine once ...)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: JTextArea

    Wow.. so the a point is in HTML? i thought the JTextPane will had some Methods for that option.. pfff i have to Read a lot about JTextPane.. thx you for the info!

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTextArea

    Quote Originally Posted by ShadowWalker View Post
    Wow.. so the a point is in HTML? i thought the JTextPane will had some Methods for that option.. pfff i have to Read a lot about JTextPane.. thx you for the info!
    Yep, read the API documentation of its superclass (the JEditorPane class); it can handle plain text, html text and rtf (Rich Text Format); I only played with the first two formats; it is easy: simply feed html text to that thing and voila, there it shows.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: JTextArea

    Before i change my project i would like to save it as it is and to make it Runnable Jar File..
    i use Eclipse to do this.. and when i was making my project into Jar Eclipse Pop Up an error :
    Exported with compile Warnings : WordPad/src/WordPad.java
    Exported with Compile Warnings : WordPad/src/paint/JFontChooser.java
    but why?? my Jar file works fine but maybe because it is on my computer.. can i post here a link with the file to tell me if is working correct? and to find any bug before i go on? :P if you time of course ;)

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: JTextArea

    The compiler issues warnings while compiling those files; nothing to worry about; open those source files and check for those yellow markers in the margin. If you hover your mouse over the marker(s) Eclipse tells you what the warning was.

    kind regards,

    Jos
    ShadowWalker likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JTextArea
    By YaFedImYaEatIm in forum AWT / Swing
    Replies: 3
    Last Post: 11-23-2012, 01:05 PM
  2. JTextArea
    By larry_d1990 in forum Advanced Java
    Replies: 4
    Last Post: 01-11-2011, 05:44 PM
  3. JTextArea
    By PhQ in forum AWT / Swing
    Replies: 10
    Last Post: 03-28-2010, 06:17 PM
  4. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •