Java Swing JLabel

JLabel is Swing’s easiest-to-use component. It can be used to display text and/or an icon. It is a passive component in that it does not respond to user input. JLabel defines several constructors:

JLabel(Icon icon)
JLabel(String str)
JLabel(String str, Icon icon, int align)

Here, str and icon are the text and icon used for the label. The align argument specifies the horizontal alignment of the text and/or icon within the dimensions of the label. It must be one of the following values: LEFT, RIGHT, CENTER, LEADING, or TRAILING. These constants are defined in the SwingConstants interface, along with several others used by the Swing classes.

Example:

import java.awt.*;
import javax.swing.*;
public class Label extends JApplet {
public void init()
{
try
{
SwingUtilities.invokeAndWait( new Runnable()
{
public void run() {
makeGUI();
}
});
}
catch(Exception exc)
{
System.out.println("Can't create because of " + exc);
}
}
private void makeGUI()
{
ImageIcon i1 = new ImageIcon("India.gif");
JLabel jl = new JLabel("India", i1, JLabel.CENTER);
add(jl);
}
}