GUI07-Swing03

2021-03-03 18:28

阅读:635

标签:ram   信息   string   ebe   item   void   lld   com   tar   

3.6列表

  • 下拉框
public class TestComboboxDemo01 extends JFrame {
    public TestComboboxDemo01(){
        Container container = this.getContentPane();
        JComboBox comboBox = new JComboBox();
        comboBox.addItem(null);
        comboBox.addItem("苹果");
        comboBox.addItem("香蕉");
        comboBox.addItem("梨子");

        container.add(comboBox);

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setBounds(100,100,300,70);
        setVisible(true);
    }

    public static void main(String[] args) {
        new TestComboboxDemo01();
    }
}

技术图片

  • 列表框
public class TestComboboxDemo02 extends JFrame {
    public TestComboboxDemo02(){
        Container container = this.getContentPane();
        Vector vector = new Vector();
        JList list = new JList(vector);
        vector.add("土豆");
        vector.add("黄瓜");
        vector.add("洋葱");
        container.add(list);

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setBounds(100,100,300,100);
        setVisible(true);
    }

    public static void main(String[] args) {
        new TestComboboxDemo02();
    }
}

技术图片

  • 应用场景
    • 下拉框,在多个选项中选择单个选项
    • 列表,展示信息,一般动态扩容!

3.7文本框

  • 文本框

-```java
public class TestComboboxDemo04 extends JFrame {
public TestComboboxDemo04(){
Container container = this.getContentPane();
JTextField textField1 = new JTextField("hello");
JTextField textField2 = new JTextField("World");

      container.add(textField1,BorderLayout.NORTH);
      container.add(textField2,BorderLayout.SOUTH);
      setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      setBounds(100,100,300,100);
      setVisible(true);
  }

  public static void main(String[] args) {
      new TestComboboxDemo04();
  }

}


![文本框](https://gitee.com/XuDa1997/imagebed/raw/master/images/GUI/GUI05/FYHT4HiYr!ZG.png)

- 密码框

```java
public class TestComboboxDemo03 extends JFrame {
    public TestComboboxDemo03(){
        Container container = this.getContentPane();
        JPasswordField passwordField = new JPasswordField();
        passwordField.setEchoChar(‘*‘);

        container.add(passwordField);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setBounds(100,100,300,70);
        setVisible(true);
    }

    public static void main(String[] args) {
        new TestComboboxDemo03();
    }
}

技术图片

  • 文本框
    public class JScrollDemo extends JFrame {
    public JScrollDemo() {
        Container container = this.getContentPane();
        //文本域
        JTextArea textArea = new JTextArea(20,50);
        textArea.setText("你好 明天");
        JScrollPane scrollPane = new JScrollPane(textArea);
        container.add(scrollPane);

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
        setBounds(100,100,300,400);
    }

    public static void main(String[] args) {
        new JScrollDemo();
    }
}

GUI07-Swing03

标签:ram   信息   string   ebe   item   void   lld   com   tar   

原文地址:https://www.cnblogs.com/xd-study/p/12966802.html


评论


亲,登录后才可以留言!