
i want to set font size of a string which will added in a label.will u please provide code for it

Hi Friend,
There are two ways:
1)
import java.awt.*;
import javax.swing.*;
class LabelExample
{
public static void main(String[] args)
{
JFrame f=new JFrame();
f.setLayout(null);
JLabel l=new JLabel("Hello");
l.setFont(new Font(null,Font.BOLD,30));
l.setBounds(20,20,120,50);
l.setForeground(Color.red);
f.add(l);
f.setVisible(true);
f.setSize(300,100);
}
}
2)
import javax.swing.*;
class LabelExample
{
public static void main(String[] args)
{
JFrame f=new JFrame();
f.setLayout(null);
JLabel l=new JLabel();
l.setBounds(20,20,120,50);
String st="<html><font size='30' color='red'>Hello</font></html>";
l.setText(st);
f.add(l);
f.setVisible(true);
f.setSize(300,100);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.