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

7 Years
Discussion Span
Last Post by kubiak

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?


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


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.

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.


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.