下拉框、列表框
作者:互联网
列表
- 下拉框
package com.wang.gui.lesson06;
import javafx.scene.control.ComboBox;
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.setSize(500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new TestComboboxDemo01();
}
}
- 列表框
package com.wang.gui.lesson06;
import javax.swing.*;
import java.awt.*;
import java.util.Vector;
public class TestComboboxDemo02 extends JFrame {
public TestComboboxDemo02() {
Container container = this.getContentPane();
//生成列表的内容
String[] contents = {"1", "2", "3"};
Vector vector = new Vector();
//列表中需要放入内容
JList list = new JList(contents);
JList list2 = new JList(vector);
vector.add("张三");
vector.add("李四");
vector.add("王五");
container.add(list);
container.add(list2);
this.setVisible(true);
this.setSize(500, 350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo02();
}
}
- 应用场景
- 选择地区,或者一些单个选项,尽量选用下拉框
- 列表,展示信息,一般是动态扩容!
标签:status,列表框,container,public,add,new,import,下拉框 来源: https://www.cnblogs.com/wshjyyysys/p/15856990.html