0

private static final Font FNT_GIVEN = new Font("SanSerif", Font.BOLD, 20);

I want to put the color for this font for example red, can someone help me??? I am working in awt.

Edited by pritaeas: fixed formatting

5
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by kubiak
0

How it work with setForeground() I am new in Java. Please help!

Font FNT_GIVEN = new Font("SanSerif", Font.BOLD, 20); //font
Color CLR_GIVEN = Color.LIGHT_GRAY; //color

How to put in this method?

0

don't shout

I'm talking about set Color for text inside Componets (f.e. Swing JLabel/Awt Label, Swing JTextField/Awt TextField)

and NormR1 (correctly) there are exist method for painting in Graphics (as you can see that in code first post under your ...)

edit: I forgot method setColor()

Edited by mKorbel: n/a

0

Hi kubiac
The point you may be missing is that the color isn't associated with the font directly. The font defines shapes that need to be drawn, but they are drawn using the foreground color for the place where they are being drawn. So, for example. if you are using a JLabel you set the foreground color of the JLabel to the color you want to see your text in.

0
JLabel My_Label = new JLabel ("My Label");
My_Label.setFont (new Font ("SansSerif", Font.BOLD, 20));
My_Label.setForeground (Color.LIGHT_GRAY);

The point... You set the colour of a label, not a font.

0

thanks a lot :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.