Solved

Displaying colors in textfield

Posted on 2002-04-27
9
174 Views
Last Modified: 2010-03-31
I 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.
0
Comment
Question by:sunilvirus
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6974428
JTextField does not support this.
You'll need to use descendant of JEditorPane to achieve this.
0
 

Author Comment

by:sunilvirus
ID: 6975197
how should i do in JEditorPane if not possible in JTextField
0
 
LVL 92

Expert Comment

by:objects
ID: 6975689
One possibility is to dfine your fomatting using HTML, and display this in your JEditorPane.
0
 

Author Comment

by:sunilvirus
ID: 6977698
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 6978752
0
 

Author Comment

by:sunilvirus
ID: 6983816
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.
0
 

Author Comment

by:sunilvirus
ID: 6983817
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.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992311
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
0
 

Expert Comment

by:SpideyMod
ID: 8048114
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 46
base64 decode encode 12 119
servlet doXXX methods 3 31
why cannot we forward request once the response is committed 2 33
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now