Solved

Displaying colors in textfield

Posted on 2002-04-27
9
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

752 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