码迷,mamicode.com
首页 > Windows程序 > 详细

GUI07-Swing03

时间:2020-05-26 18:06:37      阅读:71      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!