Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] changing label color?

Started by role May 18, 2003 at 9:52 PM 2 replies 250+ views
Original Post
role
role
can i simply change JLabel or other Swing component font color? maybe this is a dummy question, but i can''t find it anywhere.....
Ditto Brother Rat
Ditto Brother Rat
You can use html tags in Swing stuff.

new JLabel("<html><font color=red>Hello</font></html>;

I think that works. Might need quotes around the name of the colour.
CaptainJester
CaptainJester
Use setForeground(Color) to set the text color.
Use setBackground(Color) to set the background color.

You can find refrence to these in java.awt.Component. It is the base of all visual components, so it contains a lot of the functionality.



First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
role
role
wow thanxx CaptainJester
it works!
stupid me, i look only at JLabel doc and JComponent doc

i haven''t use html in swing Ditto Brother Rat, i''ll try it later.

thanx anyone

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.