GUI07-Swing03
2021-03-03 18:28
标签:ram 信息 string ebe item void lld com tar -```java } GUI07-Swing03 标签:ram 信息 string ebe item void lld com tar 原文地址:https://www.cnblogs.com/xd-study/p/12966802.html3.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文本框
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();
}
}