JDK-8265043 : Focus is stuck in radio button group post JDK-8033699
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Delivered
  • Submitted: 2021-04-12
  • Updated: 2022-03-29
  • Resolved: 2022-03-29
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
JDK-8033699 has changed the behavior of focus traversal of radio button group by Tab key.

Yet there are cases where the focus traversal doesn't work in Java 8 as expected and even where the focus gets stuck in the radio button group. In the latter case, navigation of components is broken, it's hard to move focus to another component.

The attached RadioButtonGroupFocusTest.java demonstrates the case where focus gets stuck inside the radio button group. When the app starts, the selected radio button ‘A’ has the focus. Press Tab — the focus moves to ‘C’. Now the focus is stuck: the focus does not move when you press Tab or Shift-Tab.

In the sample app, the buttons are added to the panel in the following order: ‘A’, ‘B’, ‘C’, ‘D’. Yet they're added to the ButtonGroup in a different order: ‘D’, ‘C’, ‘A’, ‘B’. If you add the radio buttons to the group in the same order, the focus doesn't get stuck in the radio button group.
Comments
There are two bugs which affect JDK 11, 17 and mainline: • JDK-8277202: Create a test to cover independent ButtonModel implementation for JToggleButton • JDK-8277243: Cast to DefaultButtonModel to access getGroup() is unnecessary These do not affect Java 8 because DefaultButtonModel is the only way to call getGroup(). In JDK 10, the ButtonModel interface was updated and now contains getGroup() method which was missing previously. It was done under JDK-8182577: Exception when Tab key moves focus to a JCheckbox with a custom ButtonModel JDK-8182577 is backported to Java 8 but the ButtonModel interface remains unchanged because it cannot be updated in Java 8 without breaking existing applications.
25-02-2022

There are a few test issues that need to be addressed in mainline and then backported to 8u: • JDK-8280818: Expand bug8033699.java to iterate over all LaFs • JDK-8280821: Expand bug8075609.java to iterate over all LaFs • JDK-8280820: Clean up bug8033699 and bug8075609.java tests: regtesthelpers aren't used This list is not comprehensive. More bugs could be submitted.
25-02-2022

With the above fixes backported to 8u, the behaviour of Java 8 is aligned with that of JDK 11 and 17 as well as the mainline.
25-02-2022

The remaining fix for JDK-8074883: “Tab key should move to focused button in a button group” has been backported to 8u and 7u. Now focus traversal in 8u and 7u for radio buttons in a button group is the same as in later versions of Java.
01-02-2022

More fixes backported to 8u: • JDK-8182577: Exception when Tab key moves focus to a JCheckbox with a custom ButtonModel • JDK-8259237: Demo selection changes with left/right arrow key JDK-8182577 is a regression from JDK-8154043 which I missed. The regression was reported for 8u311 in JDK-8276986.
14-12-2021

More fixes backported to 8u: • JDK-8167160: [TEST_BUG][PIT] failure of javax/swing/JRadioButton/8033699/bug8033699.java • JDK-8208640: [a11y] [macos] Unable to navigate between Radiobuttons in Radio group using keyboard. • JDK-8249548: backward focus traversal gets stuck in button group • JDK-8233555: [TESTBUG] JRadioButton tests failing on MacoS • JDK-8269920: JRadioButton/8033699/bug8033699.java fails on macOS
31-08-2021

Backported to 11u: • JDK-8249548: backward focus traversal gets stuck in button group • JDK-8259237: Demo selection changes with left/right arrow key. No need to press space for selection. JDK-8259237 is a regression from JDK-8249548. Both were missing from 11u.
31-08-2021

JDK-8033699 caused many regressions. The regressions have been resolved in the latest JDK (17). JDK 11 also works fine. Yet these fixes haven't been backported to 8u. The following fixes are backported to resolve the regressions: • JDK-8226892: ActionListeners on JRadioButtons don't get notified when selection is changed with arrow keys (in 8u since 8u251) • JDK-8172509: [TEST_BUG] [macosx] Failure of the new test java/awt/Focus/FocusTraversalPolicy/ButtonGroupLayoutTraversal/ButtonGroupLayoutTraversalTest.java • JDK-8221902: PIT: javax/swing/JRadioButton/FocusTraversal/FocusTraversal.java fails on ubuntu • JDK-8167284: [TESTBUG] [PIT] possible regression: javax/swing/JRadioButton/FocusTraversal/FocusTraversal.java • JDK-8268518: Add headful keyword to LayoutFocusTraversalPolicy.java • JDK-8154043: Fields not reachable anymore by tab-key, because of new tabbing behaviour of radio button groups. • JDK-8130430: [TEST_BUG] remove unnecessary internal calls from javax/swing/JRadioButton/8075609/bug8075609.java • JDK-8266348: Add "headful" to javax/swing/JRadioButton/FocusTraversal/FocusTraversal.java • JDK-8129940: JRadioButton does not honor non-standard FocusTraversalKeys
06-08-2021