- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch79 {
- public static void main(String[] args) {
- JFrame fm=new JFrame("標籤元件");
- JLabel lb1=new JLabel("預設");
- JLabel lb2=new JLabel("靠左");
- JLabel lb3=new JLabel("置中",JLabel.CENTER);
- JLabel lb4=new JLabel("靠右",JLabel.RIGHT);
- JLabel lb5=new JLabel("其他");
- fm.setBounds(100, 100, 200, 200);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- lb1.setBounds(10, 10, 180, 30);
- lb2.setBounds(10, 40, 180, 30);
- lb3.setBounds(10, 70, 180, 30);
- lb4.setBounds(10, 100, 180, 30);
- lb5.setBounds(10, 130, 180, 30);
- fm.add(lb1);
- fm.add(lb2);
- fm.add(lb3);
- fm.add(lb4);
- fm.add(lb5);
- }
- }
複製代碼 |