Member Avatar for kubiak

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.

Font

nothing to do with displayed

Color

,

setForeground()

is method what you looking for

Also look at the Graphics class. It has methods for controlling display.

Member Avatar for 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()

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.

Member Avatar for hfx642
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.

@hfx642: I think I just said that, except I left the OP to write his own code his own homework.

Member Avatar for kubiak

thanks a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.