JDK-8182695 : Exception when Tab key moves focus to a JCheckbox with a custom ButtonModel
  • Type: CSR
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 10
  • Submitted: 2017-06-22
  • Updated: 2024-04-23
  • Resolved: 2017-06-28
Related Reports
CSR :  
Description
Summary
-------
Add getModel() method to ButtonModel interface.

Problem
-------
As stated in JDK-8182577, when a custom ButtonModel is used and keyboard focus is moved by pressing TAB key, then in LayoutFocusTraversalPolicy.accept() method, it typecasts buttonmodel object to JToggleButton.ToggleButtonModel which results in ClassCastException.

Solution
--------

Added getModel() method to ButtonModel interface [src/java.desktop/share/classes/javax/swing/ButtonModel.java] would result in custom ButtonModel to implement this method. Also, LayoutFocusTraversalPolicy.accept() has been modified to store the model object as ButtonModel object instead of wrongly assuming as JToggleButton.ToggleButtonModel.
Review thread : http://mail.openjdk.java.net/pipermail/swing-dev/2017-June/007521.html

Specification
-------------

    /**
     * Returns the group that the button belongs to.
     * Normally used with radio buttons, which are mutually
     * exclusive within their group.
     *
     * @implSpec By default, this method returns {@code null}.
     * Subclasses should return the group set by setGroup().
     * 
     * @return the <code>ButtonGroup</code> that the button belongs to
     * @since 10
     */
    default ButtonGroup getGroup() {
        return null;
    }

Comments
I have changed it for current @implSpec.
29-06-2017

Moving to approved. I find the wording "The default implementation..." recommended by Alan to be more informative. Please consider changing this throughout swing. (Such a change would not require a CSR.)
28-06-2017

I have seen usage of "By default" in swing. For ex. http://hg.openjdk.java.net/jdk10/client/jdk/file/a00c069b6a3b/src/java.desktop/share/classes/javax/swing/InputVerifier.java#l142
28-06-2017

Re-pending the request. Please update the specification text in the request to include the @implSpec tag. Making that update only in the webrev is not sufficient; thanks.
27-06-2017

In other areas, we've used "The default implementation ..." in the @implSpec description rather than "By default ...".
27-06-2017

Addressed in http://cr.openjdk.java.net/~psadhukhan/8182577/webrev.04/
27-06-2017

/** * Returns the group that the button belongs to. * Normally used with radio buttons, which are mutually * exclusive within their group. * * @implSpec By default, this method returns {@code null}. * Subclasses should return the group set by setGroup(). * * @return the <code>ButtonGroup</code> that the button belongs to * @since 10 */ default ButtonGroup getGroup() { return null; }
27-06-2017

Moving the request to pended since a default method should have an @implSpec tag describing what the method does. Please re-finalize once this is addressed.
23-06-2017

Correcting Scope to "SE" since Java SE API is being modified.
23-06-2017