Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Displaying colors in textfield

Posted on 2002-04-27
9
Medium Priority
?
183 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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
 
LVL 92

Accepted Solution

by:
objects earned 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

927 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