Guest User

Untitled

a guest
Sep 4th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. package LabelFrame;
  2.  
  3. import java.awt.FlowLayout;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.SwingConstants;
  7. import javax.swing.Icon;
  8. import javax.swing.ImageIcon;
  9.  
  10. public class LabelFrame extends JFrame
  11. {
  12.  
  13.     private final JLabel label1; //JLabel with just text
  14.     private final JLabel label2; //JLabel constructed with text and icon
  15.     private final JLabel label3; //JLabel with added text and icon
  16.  
  17.    
  18.         //LabelFrame constructor adds JLabels to JFrame
  19.     public LabelFrame()
  20.     {
  21.         super("Testing JLabel");
  22.         setLayout(new FlowLayout());//set frame layout
  23.  
  24.         //JLabel constructor with a string argument
  25.         label1 = new JLabel("Label with text");
  26.         label1.setToolTipText("This is label1");
  27.         add(label1);//add label1 to JFrame
  28.  
  29.         //JLabel constructor with string, Icon and alignment arguments
  30.         Icon bug = new ImageIcon(getClass().getResource("bug.jpg"));
  31.         label2 = new JLabel("Label with text and icon", bug, SwingConstants.LEFT);
  32.         label2.setToolTipText("This is label2");
  33.         add(label2);//add label2 to JFrame
  34.  
  35.         label3 = new JLabel();//JLabel constructor no arguments
  36.         label3.setText("Label with icon and text at the bottom");
  37.         label3.setIcon(bug);//add icon to the JLabel
  38.         label3.setHorizontalTextPosition(SwingConstants.CENTER);
  39.         label3.setVerticalTextPosition(SwingConstants.BOTTOM);
  40.         label3.setToolTipText("This is label3");
  41.         add(label3);
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment