wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How Can I Colorize Text? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How Can I Colorize Text?" Watch "How Can I Colorize Text?" New topic
Author

How Can I Colorize Text?

Lazaros Lazarou
Greenhorn

Joined: Feb 13, 2001
Posts: 2
I was wondering if anybody knows how can i colorise text.
for example;
class Aclass{
private Label alabel;
public Aclass(){
alabel=new Label();]
alabel.setText("HELLO WORLD");
}
}
Is there any way to make the text "HELLO WORLD" colored
before i display it on the label?
thanks in advance.
Lazaros
Joseph Russell
Ranch Hand

Joined: Jan 08, 2001
Posts: 290
For a label you use alabel.setForeground( Color.red );
You can use black, blue, cyan, red, green, gray, darkgray, lightgray, magenta, orange, pink, white or yellow.
Joe
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
You can use the setForeground() and setBackground() methods on pretty much all of the atomic AWT and Swing components.


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
One thing to keep in mind when using the .setBackground(Color) method on Swing components is that by default Swing components are not opaque. This means that they are by default transparent. So if you want to use the setBackground method on Swing a component, you must also make the component non-transparent by using the .setOpaque(true) method. Otherwise your color won't show up.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You can also define more colors than already defined (black, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white, & yellow) by using RGB (or RGBA) values to construct new colors, like this :

The int values sent to the constructor must be in the range 0 - 255. There is also another constructor that takes float values in the range of 0.0 - 1.0 (to specify percentage of R, G, and B in the color).
HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Can I Colorize Text?
 
Similar Threads
avoiding flickering
Rotate text field
Help with ALabel - or instance variable which will hold an array
Help! I need help w/ALabel(s) to display messages
how to get the answer as 15 for this code