JDK-4066394 : ButtonGroup - cannot reset the model to the initial unselected state
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.6,1.2.0,1.4.2,5.0,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,linux,solaris_2.5,windows_nt,windows_2000 generic,linux,solaris_2.5,windows_nt,windows_2000
  • CPU: generic,x86
  • Submitted: 1997-07-22
  • Updated: 2017-05-16
  • Resolved: 2005-09-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b53Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
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
WORK AROUND Name: keR10081 Date: 08/28/2001 use setSelected(null,boolean) to clear selection. ======================================================================
28-09-2004

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 ======================================================================
03-11-2003

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 ======================================================================
03-11-2003