import java.awt.*; import javax.swing.*; public class SampleLabel { public static void main(String args[]) { JFrame application = new JFrame("Label Demonstrator"); // Choose one of the following layout managers application.setLayout(new FlowLayout()); //application.setLayout(new GridLayout()); // JLabel constructor with a string argument JLabel label = new JLabel("Label with new text"); label.setToolTipText("This is label1"); application.add(label); // JLabel constructor with string, Icon and // alignment arguments Icon bug = new ImageIcon("bug1.png"); label = new JLabel("Label with text and icon", bug, SwingConstants.LEFT); label.setToolTipText("This is label2"); application.add(label); // JLabel constructor no arguments label = new JLabel(); label.setText("Label with icon and text at bottom"); label.setIcon(bug); label.setHorizontalTextPosition(SwingConstants.CENTER); label.setVerticalTextPosition(SwingConstants.BOTTOM); label.setToolTipText("This is label3"); application.add(label); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.setSize(275, 170); application.setVisible(true); } } /******************************************************************************* * Based on example code from Deitel & Associates, Inc. Prentice Hall. (2002) *******************************************************************************/