Sunday, 10 May 2015

Tutorial On Fonts Of Label In Java

J Label class is used to display text in frame it can also be useful to display images as we done in other examples.Some times we need to change size and font of label in our programs to make it more beautiful.Question is how to change size and font of here is the solution to do this in this tutorial i have use setFont() method to change size and font style of text.We have not use any font style in label1 as you can see it and in second label we have use Serif Font with a size of 26.In third label we have use  Broadway font with 20 font size we have also use BOLD  font in this  label.In last  label we have set label font as Forte with 25 font size.

CODING:

import javax.swing.*;
import java.awt.*;
class myjframe1 extends JFrame
{

public myjframe1() 
{

setTitle("Fonts Of Label");

setDefaultCloseOperation(EXIT_ON_CLOSE);      
JLabel  l1= new JLabel("label without font");
JLabel  l2= new JLabel("label with Serif Font");
JLabel  l3= new JLabel("label with Broadway & Bold Font");
JLabel  l4= new JLabel("label with Forte & Italic font");
l2.setFont(new Font("Serif", Font.PLAIN, 26));
l3.setFont(new Font("Broadway", Font.BOLD, 20));
l4.setFont(new Font("Forte", Font.ITALIC, 25));
setLayout(null);
l1.setBounds(50, 20, 200,100);
l2.setBounds(50, 60, 250,100);
l3.setBounds(50, 100, 500,100);
l4.setBounds(50, 150, 500,100);
add(l1);
add(l2);
add(l3);
add(l4);
setSize(300, 200);
setVisible(true);
}
}
class simpframe
{
public static void main(String args[])
{
myjframe1 x= new myjframe1();
}
}

OUTPUT:


No comments:

Post a Comment