简体   繁体   中英

Update JComboBox immediately upon JComboBox selection

I have a JComboBox. I would like it to work so that if a certain item is selected ("Other"), immediately, several more items are displayed in the same combo box (something like a submenu, but inside the combo box). I'm having a devil of a time getting this to work.

Does anyone have any ideas on how to do this?

EDIT: misunderstood your question!

I assume that you are clicking on an item in the JComboBox? Than simply add this code

comboOther.addActionListener (new ActionListener () {
        public void actionPerformed(ActionEvent e) {
            comboOther.addItem("new item 1");
            comboOther.addItem("new item 2");
            comboOther.addItem("new item 3");
            // more
        }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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