简体   繁体   English

自动刷新Java中的combobox

[英]auto refresh of combobox in java

hello everyone just need a bit of help here: 你好,每个人都需要一点帮助:

            JComboBox comboBox = new JComboBox();
        comboBox.setModel(new DefaultComboBoxModel(new String[] {"Select", "Single", "Twin", "Double", "Suit", "Conference"}));


        String[] single = d.getAvaSinglelist().toArray(new String[d.getAvaSinglelist().size()]);
        String[] Dbroon = d.getAvaDoublelist().toArray(new String[d.getAvaDoublelist().size()]);
        String[] Twin = d.getAvaTwinlist().toArray(new String[d.getAvaTwinlist().size()]);
        String[] Suit = d.getAvaSuitslist().toArray(new String[d.getAvaSuitslist().size()]);
        String[] conf = d.getAvaConferencelist().toArray(new String[d.getAvaConferencelist().size()]);
        JComboBox comboBox_1 = new JComboBox();

            if(comboBox.getSelectedItem().equals("Single")){
                comboBox_1.setModel(new DefaultComboBoxModel(single));
            }

            if(comboBox.getSelectedItem().equals("Twin")){
                comboBox_1.setModel(new DefaultComboBoxModel(Dbroon));
            }
            if(comboBox.getSelectedItem().equals("Double")){
                comboBox_1.setModel(new DefaultComboBoxModel(Twin));
            }
            if(comboBox.getSelectedItem().equals("Suit")){
                comboBox_1.setModel(new DefaultComboBoxModel(Suit));
            }
            if(comboBox.getSelectedItem().equals("Conference")){
                comboBox_1.setModel(new DefaultComboBoxModel(conf));
            }

so what i want to do and cant find out how is to refresh the second combobox based on the selected item of the first one in a dynamic mode but as you guys can see also i have no idea every tip is welcome 所以我想做的是无法找到如何在动态模式下根据第一个组合框的选定项刷新第二个组合框,但是正如你们看到的那样,我也不知道每个提示都欢迎

Add an ActionListener to your first JComboBox . ActionListener添加到第一个JComboBox Then add the logic for updating the second combo box inside that code. 然后在该代码中添加用于更新第二个组合框的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM