Steve Cohen
Steve Cohen

Reputation: 4859

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?

Upvotes: 0

Views: 201

Answers (1)

Captain Obvious
Captain Obvious

Reputation: 785

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
        }
});

Upvotes: 2

Related Questions