how should i do in JEditorPane if not possible in JTextField
Main Topics
Browse All TopicsI want to display the text with different colors in TextFiled(or JTextField). What i actually want is that i want some of the text to be in one color and some other text to be in other color.
I tried changing the color using the function
setForeground(Color c)
but the color of the entire text is changing.
I think you understand my problem.
thanks in advance.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Is there no possibility that it can be done in a JTextArea or JEditorPane without using HTML.
This is because i am redirecting the output of another program(in C) to my java program. i want to change the color of the text depending upon the keywords used in the input. The entire thing is to be done simultaneously.
i.e the C program will continiously output the text which will be read by the java program and displayed with appropriate color.
Yes, have a look at the following:
http://developer.java.sun.
hello objects,
First let me thank for guiding me to a good resource.
i have tried the specified code in a slightly different way.
it is working fine if i type it directly in the window.
but when i am appending the string read from the console using the method
insertString()
the appended text is being displayed in white color(Foreground color)
but if i type it directly in the window it is being typed in the required color.
hello objects,
First let me thank for guiding me to a good resource.
i have tried the specified code in a slightly different way.
it is working fine if i type it directly in the window.
but when i am appending the string read from the console using the method
insertString()
the appended text is being displayed in white color(Foreground color)
but if i type it directly in the window it is being typed in the required color.
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: objects
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venci75
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: objectsPosted on 2002-04-27 at 21:15:47ID: 6974428
JTextField does not support this.
You'll need to use descendant of JEditorPane to achieve this.