1

Is it possible that the items in jComboBox change by clicking a jRadioButton? For instance: the first jRadioButton is selected and there are five options in jComboBox. When you click another jRadiobuttonfrom the same button group, the options from jComboBox are replaced with the new ones. Do I need to use ActionListener?

lol
  • 231
  • 1
  • 10

1 Answers1

2

Yes it is. But I recommend using ItemListener instead of ActionListener. In the itemStateChanged methode, check if radio button is selected.

radioButton.addItemListener(new ItemListener() {        
    @Override
    public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            //change your combobox
        }
        else if (e.getStateChange() == ItemEvent.DESELECTED) {
            //change to another
        }
    }
});
destraaaa
  • 96
  • 5