Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package LabelFrame;
- import java.awt.FlowLayout;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.SwingConstants;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- public class LabelFrame extends JFrame
- {
- private final JLabel label1; //JLabel with just text
- private final JLabel label2; //JLabel constructed with text and icon
- private final JLabel label3; //JLabel with added text and icon
- //LabelFrame constructor adds JLabels to JFrame
- public LabelFrame()
- {
- super("Testing JLabel");
- setLayout(new FlowLayout());//set frame layout
- //JLabel constructor with a string argument
- label1 = new JLabel("Label with text");
- label1.setToolTipText("This is label1");
- add(label1);//add label1 to JFrame
- //JLabel constructor with string, Icon and alignment arguments
- Icon bug = new ImageIcon(getClass().getResource("bug.jpg"));
- label2 = new JLabel("Label with text and icon", bug, SwingConstants.LEFT);
- label2.setToolTipText("This is label2");
- add(label2);//add label2 to JFrame
- label3 = new JLabel();//JLabel constructor no arguments
- label3.setText("Label with icon and text at the bottom");
- label3.setIcon(bug);//add icon to the JLabel
- label3.setHorizontalTextPosition(SwingConstants.CENTER);
- label3.setVerticalTextPosition(SwingConstants.BOTTOM);
- label3.setToolTipText("This is label3");
- add(label3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment