United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4066394 : ButtonGroup - cannot reset the model to the initial unselected state

Details
Type:
Enhancement
Submit Date:
1997-07-22
Status:
Resolved
Updated Date:
2005-09-20
Project Name:
JDK
Resolved Date:
2005-09-20
Component:
client-libs
OS:
solaris_2.5,windows_nt,linux,generic,windows_2000
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1.6,1.2.0,1.4.2,5.0,6
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:

Sub Tasks

Description
ButtonGroup.setSelected(ButtonModel, boolean) as it is currently defined does not need the boolean, as if the boolean is false, it does nothing.  I assume that if the boolean is false, it should set the button to false, but it does not as currently defined.

Without this there is no way to set the ButtonGroup back to its initial unselected state.

                                    

Comments
EVALUATION

This functionality should be added.
jeff.dinkins@Eng 1998-03-16

I agree. This request seems rather popular. There are multiple ways that we could implement this with the current API:

1) AbstractButton.setSelected(false) on a selected button.
2) ButtonGroup.setSelected(currentModel, false)
3) ButtonGroup.setSelected(null, true)

We could also add a clearSelection method.

###@###.### 2001-11-13

Also, when fixing this, we may want to look into the fact that setSelected(), with a model that doesn't belong to a button in the group, clears the selection.
###@###.### 2001-11-13

Name: ibR10256			Date: 11/03/2003


I think the both two first suggested ways are appropriate (actually,
implementing the second way makes the first way working too).
Although this changes the method behaviour so will probably require a
CCC request.
A check that doesn't allow to change the state of a model that doesn't
belong to the group can also be added to ButtonGroup.setSelected.

###@###.### 2003-11-03


======================================================================
                                     
2003-11-03
SUGGESTED FIX

Name: ibR10256			Date: 11/03/2003


------- ButtonGroup.java -------
*** /tmp/sccs.EOaqJb    Mon Nov  3 17:42:59 2003
--- ButtonGroup.java    Mon Nov  3 17:42:33 2003
***************
*** 130,143 ****
       *   selected, otherwise <code>false</code>
       */
      public void setSelected(ButtonModel m, boolean b) {
!         if (b && m != null && m != selection) {
!             ButtonModel oldSelection = selection;
!             selection = m;
!             if (oldSelection != null) {
!                 oldSelection.setSelected(false);
              }
!             m.setSelected(true);
!         } 
      }
  
      /**
--- 130,167 ----
       *   selected, otherwise <code>false</code>
       */
      public void setSelected(ButtonModel m, boolean b) {
!         if (m != null) {
!             if ((b && m == selection) || (!b && m != selection)) {
!                 return;
              }
!             // check that the model belongs to the group
!             if (m instanceof DefaultButtonModel) {
!                 if (((DefaultButtonModel)m).getGroup() != this) {
!                     return;
!                 }
!             } else {
!                 int i = 0;
!                 while (i < buttons.size() &&
!                         ((AbstractButton)buttons.elementAt(i)).getModel() != m) {
!                     i++;
!                 }
!                 if (i == buttons.size()) {
!                     return;
!                 }
!             }
!             
!             if (b) {
!                 ButtonModel oldSelection = selection;
!                 selection = m;
!                 if (oldSelection != null) {
!                     oldSelection.setSelected(false);
!                 }
!                 m.setSelected(true);
!             } else {
!                 selection = null;
!                 m.setSelected(false);
!             }
!         }
      }
  
      /**

###@###.### 2003-11-03



======================================================================
                                     
2003-11-03
WORK AROUND



Name: keR10081			Date: 08/28/2001

use setSelected(null,boolean) to clear selection.



======================================================================
                                     
2004-09-28



Hardware and Software, Engineered to Work Together