Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8182695

Exception when Tab key moves focus to a JCheckbox with a custom ButtonModel

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P3
    • 10
    • client-libs
    • None
    • minimal
    • Java API
    • SE

    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;
      }

      Attachments

        Issue Links

          Activity

            People

              psadhukhan Prasanta Sadhukhan
              webbuggrp Webbug Group
              Kevin Rushforth, Semyon Sadetsky (Inactive), Sergey Bylokhov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: