3.6 列表
-
下拉框
package GUI.Swing; import javax.swing.*; import java.awt.*; public class TestComboboxDemo01 extends JFrame { public TestComboboxDemo01(){ Container container = this.getContentPane(); //下拉框 JComboBox status = new JComboBox(); status.addItem(null); status.addItem("鹿鹿"); status.addItem("的"); status.addItem("学习日记"); container.add(status); this.setVisible(true); this.setBounds(100,100,300,300); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new TestComboboxDemo01(); } }
-
列表框
package GUI.Swing; import javax.swing.*; import java.awt.*; public class TestComboboxDemo02 extends JFrame { public TestComboboxDemo02(){ Container container = this.getContentPane(); //生成列表的内容 String[] contents = {"1","2","3"}; //列表中需要放入内容 JList jList = new JList(contents); container.add(jList); this.setVisible(true); this.setBounds(100,100,300,300); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { new TestComboboxDemo02(); } }
-
应用场景:
-
选择地区,或者一些单个选项
-
列表,展示信息,一般是动态扩容的
-
3.7 文本框**
-
文本框
JTextField textField = new JTextField("xxxxxx");
-
密码框
JPasswordField jPasswordField = new JPasswordField();
-
文本域
//文本域 JTextArea textArea = new JTextArea(20, 30); textArea.setText("欢迎观看鹿鹿的学习日记!")