1

I have two JRadioButtons that will be used to sort objects in a JList in various ways. They are both members of the same ButtonGroup. However, I'd like to listen to both buttons with one actionlistener and then iterate through them to see which one was selected. What is the most effecient way of doing such?

Austin H
  • 11
  • 1

2 Answers2

1

One way of doing it is using ButtonGroup's getSelection, which returns the ButtonModel of the JRadioButton that is selected. Your ActionListener should be able to distinguish which one is selected by examining this.

Klarth
  • 2,035
  • 14
  • 26
1

The ActionListener tells you which button was clicked in the ActionEvent:

JRadioButton button = (JRadioButton)event.getSource();
camickr
  • 321,443
  • 19
  • 166
  • 288