下拉框
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.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(200,200,300,300);
}
public static void main(String[] args) {
new TestComboboxDemo01();
}
}
列表框
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.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(200,200,300,300);
}
public static void main(String[] args) {
new TestComboboxDemo02();
}
}