0
点赞
收藏
分享

微信扫一扫

GUI-study-lesson15(Swing之下拉框·列表框)

王小沫 2022-05-02 阅读 58
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();
    }
}

 

举报

相关推荐

0 条评论