How to Change Font Color of a Label in Java, Changing Font of a Label in Java


How to Change Font Color of a Label in Java, Changing Font of a Label in Java



There are several ways to change the Font of a Label in Java.We can change the font color, font size, font type, font weight etc. I am showing an example for doing these task in one example.

Example:-

import java.awt.*;
public class ChangeFont extends Frame
{
Label lbl;
public ChangeFont()
{
Font font=new Font("Curlz MT",Font.BOLD,20);
this.setSize(400,200);
this.setTitle("Change Font of a Label");
this.setLayout(null);
this.setVisible(true);
lbl=new Label("This is Sample Text");
lbl.setBounds(100,80,200,40);
lbl.setFont(font);
lbl.setForeground(Color.RED);
this.add(lbl);
}
public static void main(String st[])
{
new ChangeFont();
}

}

I am sure the above example definitely helps you.

Thanks for visiting

{ 0 comments... read them below or add one }

Post a Comment