Code
buttons.setFocusTraversalPolicyProvider(true);
buttons.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
@Override public Component getDefaultComponent(Container focusCycleRoot) {
ButtonModel selection = bg.getSelection();
for (Component c: focusCycleRoot.getComponents()) {
JRadioButton r = (JRadioButton) c;
if (r.getModel().equals(selection)) {
return r;
}
}
return super.getDefaultComponent(focusCycleRoot);
}
});
References
- [JDK-8033699] Incorrect radio button behavior - Java Bug System
- [JDK-8154043] Fields not reachable anymore by tab-key, because of new tabbing behaviour of radio button groups. - Java Bug System
- java - Get the focus in a ButtonGroup of JRadioButtons to go to the currently selected item instead of first - Stack Overflow
- The JRadioButton that is currently selected in the ButtonGroup set as the default focus component (Japanese)
No comments:
Post a Comment