Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2004

Tip: Looking for answers? Try searching our database.

Mixing font colors in a JTextArea

Thread view: 
davidol@hushmail.com - 30 Dec 2004 07:23 GMT
Dear all,

JTextArea.setForeground() sets the font color for the entire component,
but how can I have different font colors in the same area?  I want to
be able to append text in blue and red.

Cheers!
Andrew Thompson - 30 Dec 2004 07:53 GMT
> JTextArea.setForeground() sets the font color for the entire component,
> but how can I have different font colors in the same area?

Use HTML in a (non editable) JEditorPane.  Alternately you might
look to a JTextPane and manipulate the document attributes.
Google the group for examples.

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Christian Kaufhold - 31 Dec 2004 19:19 GMT
>> JTextArea.setForeground() sets the font color for the entire component,
>> but how can I have different font colors in the same area?
>
> Use HTML in a (non editable) JEditorPane.  Alternately you might
> look to a JTextPane and manipulate the document attributes.

I find this slightly misleading. There is virtually no difference
between JEditorPane and JTextPane and you may as well use either
HTML or the simple default styled text with both. As the minor
additional features of JTextPane aren't sufficient for serious
work, I would use JEditorPane, and, if editing is required,
transplant the basic input attribute logic there.

Christian
Andrew Thompson - 31 Dec 2004 23:59 GMT
>>> JTextArea.setForeground() sets the font color for the entire component,
>>> but how can I have different font colors in the same area?
[quoted text clipped - 8 lines]
> work, I would use JEditorPane, and, if editing is required,
> transplant the basic input attribute logic there.

Thanks for clarifying Christian.  I was unsure whether to mention
JTextPane since I myself had never found a use for one.  (I should
have stuck with my instincts on that one!)

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Jon Caldwell - 30 Dec 2004 14:53 GMT
> Dear all,
>
[quoted text clipped - 3 lines]
>
> Cheers!

Check out Sun's TextComponentDemo for an example
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.h
tml#TextComponentDemo



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.