Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java组合框依赖于另一个组合框_Java_Netbeans_Combobox - Fatal编程技术网

Java组合框依赖于另一个组合框

Java组合框依赖于另一个组合框,java,netbeans,combobox,Java,Netbeans,Combobox,我有一个对象的ArrayList,用于填充组合框(管理器),如下所示: testingPeople people = new testingPeople(); people.loadPeople(); ArrayList<Person> testing = new ArrayList<Person>(); testing = people.getManagerList(); for (int i=0; i < testing.size(); i++) { j

我有一个对象的
ArrayList
,用于填充
组合框
(管理器),如下所示:

testingPeople people = new testingPeople();
people.loadPeople();
ArrayList<Person> testing = new ArrayList<Person>();
testing = people.getManagerList();
for (int i=0; i < testing.size(); i++) {
    jComboBox1.addItem(testing.get(i));
}
还有其他的变化,但我还是画了个空白


有人能告诉我吗。

jcombox1
的项目侦听器中添加填充
jcombox2
对应的代码。比如说,

ItemListener itemListener = new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent evt) {
        String item = (String) evt.getItem();
        switch (item) {
            case "Item 1":
                jComboBox2.removeAllItems();
                jComboBox2.addItem("A");
                jComboBox2.addItem("B");
                jComboBox2.addItem("C");
                break;
            case "Item 2":
                jComboBox2.removeAllItems();
                jComboBox2.addItem("E");
                jComboBox2.addItem("F");
                jComboBox2.addItem("G");
                break;
        }
    }
};
jComboBox1.addItemListener(itemListener);

jcombox1
的项目侦听器中添加与填充
jcombox2
相对应的代码。比如说,

ItemListener itemListener = new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent evt) {
        String item = (String) evt.getItem();
        switch (item) {
            case "Item 1":
                jComboBox2.removeAllItems();
                jComboBox2.addItem("A");
                jComboBox2.addItem("B");
                jComboBox2.addItem("C");
                break;
            case "Item 2":
                jComboBox2.removeAllItems();
                jComboBox2.addItem("E");
                jComboBox2.addItem("F");
                jComboBox2.addItem("G");
                break;
        }
    }
};
jComboBox1.addItemListener(itemListener);

组合框的操作事件发生在组合框的值更改时,因此代码应在第一个组合框的事件处理程序中工作。

组合框的操作事件发生在组合框的值更改时,因此代码应在第一个组合框的事件处理程序中工作