Frame:下拉框,列表框

package com.tai.test02;

import javafx.scene.control.ComboBox;

import javax.swing.*;
import java.awt.*;

public class TestComboxDemo01 extends JFrame {
    public TestComboxDemo01() {

        Container container = getContentPane();
        JComboBox<Object> box = new JComboBox<>();

        box.addItem(null);
        box.addItem("1yuan");
        box.addItem("2yuan");
        box.addItem("3yuan");

        container.add(box);

        setVisible(true);
        setBounds(100,100,600,400);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new TestComboxDemo01();
    }
}
package com.tai.test02;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

public class TestComboxDemo02 extends JFrame {
    public TestComboxDemo02() {

        Container container = getContentPane();

        Vector vector = new Vector();
        //生成列表内容
        String[] contents = {"1","2","3"};

        JList list = new JList(vector);

        vector.add("1");
        vector.add("2");
        vector.add("3");

        container.add(list);

        setVisible(true);
        setBounds(100,100,600,400);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new TestComboxDemo02();
    }
}

你可能感兴趣的:(GUI)