Solved

Displaying colors in textfield

Posted on 2002-04-27
9
173 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
Comment Utility
JTextField does not support this.
You'll need to use descendant of JEditorPane to achieve this.
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:sunilvirus
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Accepted Solution

by:
objects earned 100 total points
Comment Utility
0
 

Author Comment

by:sunilvirus
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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

12 Experts available now in Live!

Get 1:1 Help Now