Title: RE: set color of JLabel text
Now you are in the realm of text components. This is *the* most complex area of Swing.
 
You will need to find a good Swing book (there is no way I could do it justice, here), then try using a custom document (which implements javax.swing.text.StyledDocument) to call setCharacterAttributes(int,int,javax.swing.text.AttributeSet,boolean)
 
Classes and interfaces that may be of interest, all in javax.swing.text:
 
AttributeSet
Document
StyledDocument
Style
 
Also note that JTextField, JTextArea and JPassword field do not support multiple text styles. You'll have to use JEditorPane, or JTextPane.
 
The O'Reilly "Java Swing" book does have an example of how to set different colours on text in a text component. That may be helpful to you.
-----Original Message-----
From: Pepelis, Aaron <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, April 03, 2001 01:07
Subject: RE: set color of JLabel text

on, this subject...
there's something that I've wanted to do for a long time.
multi-colored textfields.
I'm talking like have 4 letters in red, then 4 in blue, then 4 in red, then 4 in blue.
not that I want to have that to do a word break down of some hex values...
but I do.
Any clues how to do this?
rev aaron
-----Original Message-----
From: Greg Munt [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 03, 2001 8:06 AM
To: Pepelis, Aaron; [EMAIL PROTECTED]
Subject: Re: set color of JLabel text

Yes, that will do it.
 
But, if you want this to affect all JLabel components, you need to change the UI default value for Label.foreground. To change it to red:
 
javax.swing.UIManager.put ("Label.foreground", Color.red);
 
Alternatively you can set this via a custom LookAndFeel class, which is what I do.
-----Original Message-----
From: Pepelis, Aaron <[EMAIL PROTECTED]>
To: '[EMAIL PROTECTED]' <[EMAIL PROTECTED]>
Date: Tuesday, April 03, 2001 12:35
Subject: RE: set color of JLabel text

am I missing something?
maybe I just got done doing a radio show at 2:30am and I'm back at work at 7:30am,
but:
JLabel label = new JLabel("hello glory");
label.setForeground(Color.red);

that?
rev aaron

-----Original Message-----
From: Dmitry Beransky [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 02, 2001 12:30 PM
To: '[EMAIL PROTECTED]'
Subject: Re: set color of JLabel text


A good place to start would be
<http://java.sun.com/docs/books/tutorial/uiswing/start/index.html>.  If
you need a Visualage specific answer, I recommend posting to
<http://groups.yahoo.com/group/wsvaj>.

On Mon, 2 Apr 2001, Mario Fernandes (IT Dept. - Langley) wrote:

> Hi
>
> how do I set the color of the text appearing in a JLabel. I am using Ibm
> Visualage and the color of the text appearing  in the JLabel and the JButon
> are different.
>
>
> Thanx in advance
>
>
> Mario
>

_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to