0

I have three JRadioButtons in ButtonGroup. With keyboard navigation with TAB I can go through this JRadioButtons (change focus), with SPACE I can select JRadioButton with focus. Is it possible that with TAB will be changed not only focus but also state of JRadioButton?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1ac0
  • 2,875
  • 3
  • 33
  • 47
  • @mKorbel it's on jdialog with just 3 radiobuttons and two buttons (ok, cancel) – 1ac0 Mar 25 '13 at 20:54
  • but for JRadioButtons in the ButtonGroup is possible to select only one element (by default, I see there hack), maybe proper way for you – mKorbel Mar 25 '13 at 20:55

2 Answers2

3

Add a FocusListener to the radio button to select it once it gains focus.

camickr
  • 321,443
  • 19
  • 166
  • 288
1

Just a quick tip for other readers:

myRadioButton.addFocusListener(new FocusListener(){
    @Override
    public void focusLost(FocusEvent e){
        myRadioButton.setSelected(false);
    }
    @Override
    public void focusGained(FocusEvent e){
        myRadioButton.setSelected(true);
    }
});
1ac0
  • 2,875
  • 3
  • 33
  • 47