import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class LabelSample {
public static void main(String args[]) {
String title = "JLabel Sample";
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = frame.getContentPane();
content.setLayout(new GridLayout(2, 2));
JLabel label1 = new JLabel("Text Label");
content.add(label1);
Icon warnIcon = new ImageIcon("Warn.gif");
JLabel label2 = new JLabel(warnIcon);
content.add(label2);
JLabel label3 = new JLabel("Warning", warnIcon, JLabel.CENTER);
content.add(label3);
String htmlLabel = "HTML Label
"
+ "Multi-line";
JLabel label4 = new JLabel(htmlLabel);
content.add(label4);
frame.setSize(300, 200);
frame.setVisible(true);
}
}