其他分享
首页 > 其他分享> > 下拉框、列表框

下拉框、列表框

作者:互联网

列表

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