Colors in Java

 

 

When you use a setTextColor() or setTextBackgroundColor(), or any other method to tell Java what color you want to use, you have to put something in the brackets to specify the color. The thing you put in brackets will specify an existing color, or create a new color for Java to use.

You use an existing color object like this:

            c.setTextColor(Color.red);   or   

c.setTextBackgroundColor(Color.blue);

 

Possible color names are:

black, blue, cyan, dark_gray, gray, green, light_gray, magenta, orange, pink, red, white, and yellow.

Or you can create your own color object like this:

            c.setTextColor(new Color(128, 138, 255));   or 

c. setTextBackgroundColor(new Color(0, 100, 0));

 

The three numbers specify how much of the colors red, green and blue to mix. 255 is the maximum amount, and 0 is the minimum. new Color(0, 0, 0 ) is black, new Color(255, 255, 255 ) is white, new Color(255, 0, 0) is bright red, new Color(100, 0, 0) is dull red, and so on.

 

How do you find out the red/green/blue values for a good color?

One way to do this is to go into word, then open the font color tool, select more colors, and the custom tab. Then choose the color you want, and copy down the red, green, and blue values shown.

Choose color

 
 


Your color

 

Get red, green, and blue values