Solved

Displaying colors in textfield

Posted on 2002-04-27
9
178 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Title # Comments Views Activity
couple of eclipse 5 46
MySQL  on Tomcat 8 70
Eclipse Java import and method not resolved 4 52
Tagging and Merging on Branch 1 30
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
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…

821 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