Link to home
Start Free TrialLog in
Avatar of paramibm
paramibm

asked on

text area and string

Sir,
   I have to display the string "hello world" in a single text area in a frame (or applet) . String "hello" should be displayed in (say) blue
color and "world " in (say) red color.how can i proceed?
thanks
paramjit
ver -- JDK 1.3
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Homework? We're here to help people who have *already* produced something of their own.
 Hehehehe, CEHJ could not be more right.
Avatar of paramibm
paramibm

ASKER

sir
i had done a project in java to create Multithreaded Chat server .
 thanks
use a JTextArea (in this example, named jta) and then do something like:

jta.select(0, 5);
jta.setSelectedTextColor(Color.red);
jta.select(5, 10);
jta.setSelectedTextColor(Color.blue);
i am also having the same problem(slightly different).
see my question "Displaying colors in textfield"

one useful link given in my following is
http://developer.java.sun.com/developer/onlineTraining/GUI/Swing2/Magercises/M3/index.html

i think it will serve your purpose.
hello bobbit31

your code in not working as required.
when using the method setSelectedTextColor() for the second time,
the color applied in the first call is not being retained.
it is again changing back to the foreground color.

this is because the previous selection is lost when the new text is selected.
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: bobbit31
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange