A label is a simple control which is used to display text (non-editable) on the window. Since it does not possess any user interactive feature, it is considered as a passive control. A label is an object of
JLabel class.
Some of the constructors defined by JLabel class are as follows.
JLabel ()
JLabel(String string)
JLabel(String string, int align)
where,
string is the text used for the label
align specifies the horizontal alignment of the text contained in the label, and can have one of the following values: LEFT,RIGHT,CENTER,LEADING or TRAILING.
import java.awt.*;
import javax.swing.*;
public class JavaExampleLabelImageInJApplet extends JApplet
{
public void init()
{
Container Cntnr = getContentPane();
JLabel Lbl = new JLabel("Label",new ImageIcon("Koala.jpg"),JLabel.CENTER);
Lbl.setVerticalTextPosition(JLabel.BOTTOM);
Lbl.setHorizontalTextPosition(JLabel.CENTER);
Cntnr.add(Lbl);
}
}
/*<APPLET CODE=JavaExampleLabelImageInJApplet.class WIDTH=510 HEIGHT=210></APPLET>*/