下拉框
package Lesson06;
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,500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo01();
}
}
列表框
package Lesson06;标签:status,列表框,12,add,2022,new,import,public,contents From: https://www.cnblogs.com/RUI2022/p/16976315.html
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 contents = new Vector();
//列表中需要放入内容
JList jList = new JList(contents);
contents.add("zhangsn");
contents.add("lis");
contents.add("wangwu");
container.add(jList);
this.setVisible(true);
this.setBounds(100,100,500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestComboboxDemo02();
}
}