Search code examples
javaswingjradiobuttonbuttongroupfocuslistener

Swing JRadioButton autoselect after get focus


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?


Solution

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