GUI-study-lesson15(Swing之下拉框·列表框)
    package lesson06;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TextComboboxDemo1 extends JFrame {
    public TextComboboxDemo1() {
        Container contentPane = getContentPane();
        //下拉框
        JComboBox comboBox = new JComboBox();
        comboBox.addItem(null);
        comboBox.addItem("111");
        comboBox.addItem("222");
        comboBox.addItem("222");
        
        contentPane.add(comboBox);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.pack();
    }
    public static void main(String[] args) {
        new TextComboboxDemo1();
    }
}
 

 
 
 
package lesson06;
import javax.swing.*;
import java.awt.*;
public class TextComboboxDemo2 extends JFrame {
    public TextComboboxDemo2() {
        Container contentPane = getContentPane();
        //生产列表的内容  稀疏数组
        String[] contents = {"1","2","3"};
        //列表中需要放入内容
        JList jList = new JList(contents);
        contentPane.add(jList);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.pack();
    }
    public static void main(String[] args) {
        new TextComboboxDemo2();
    }
}
 
