JDK-4133141 : Extend Action interface to handle toggles
  • Type: Enhancement
  • Status: Resolved
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P4
  • Affected Version:
    1.2.0,1.2.2,1.3.0,1.3.1,1.3.1_06,1.4.0,1.4.1,1.4.1_01,1.4.1_03,1.4.2,5.0 1.2.0,1.2.2,1.3.0,1.3.1,1.3.1_06,1.4.0,1.4.1,1.4.1_01,1.4.1_03,1.4.2,5.0
  • OS:
    generic,linux,linux_redhat_7.2,windows_95,windows_98,windows_nt,windows_2000,windows_xp generic,linux,linux_redhat_7.2,windows_95,windows_98,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86
  • Submit Date: 1998-04-28
  • Updated Date: 2017-05-16
  • Resolved Date: 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 Availabitlity Release.

To download the current JDK release, click here.
6 b53Resolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Name: rk38400			Date: 04/28/98

I really like the Action interface (in fact, I'd
implemented it myself in a previous version of my 
system) - but what about toggles? I'd like to be
able to define a ToggleAction that has an on/off 
state. When I add it to a JToolbar, I'd get a
JToggleButton. When I add it to a JMenu, I'd get
a JCheckboxMenuItem. Setting its state to be on via
the menuitem would cause the appearance of the
JToggleButton to change automatically, etc.
The same idea could probably be extended to encompass
JRadioButton/JRadioButtonMenuItem pairs...
(Review ID: 29188)

Name: krT82822			Date: 01/24/2000

java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

Why does the new method "JToolBar.CreateActionComponent" return a JButton?
Because of this, it's not possible to create a JToggleButton for the action.

Suggestion: CreateActionComponent should return a JAbstractButton or, even
better, a Component (since buttons aren't the only thing usually visible in a
toolbar, and for example ComboBoxes could be associated with an action as well).
(Review ID: 100282)

Name: krC82822			Date: 11/02/2000

java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Right now Action and AbstractAction provides support for creating several
controls with a common behaviour and with their enabled state synchronized, but
there is no way to have several toggle buttons synchronized in such a way. I
think it could be interesting to add ToggleAction and AbstractToggleAction, so
we could have several toggle buttons with their selected state synchronized.
The additional classes could be something like this:

package javax.swing;

public interface ToggleAction extends Action
  boolean isSelected( );
  void setSelected( boolean selected );

package javax.swing;

import java.io.Serializable;
import java.awt.event.*;

public abstract class AbstractToggleAction extends AbstractAction
implements ToggleAction, Cloneable, Serializable
  protected boolean selected = false;

  public AbstractToggleAction( )
    { super( ); }

  public AbstractToggleAction( String name )
    { super( name ); }

  public AbstractToggleAction( String name, Icon icon )
    { super( name, icon ); }

  public Object clone( )
    AbstractToggleAction copy = null;
      copy = (AbstractToggleAction) super.clone( );
      copy.selected = this.selected;
    catch( CloneNotSupportedException exc )
    return copy;

  public boolean isSelected( )
    { return selected; }

  public void setSelected( boolean selected )
    if( this.selected != selected )
      this.selected = selected;
      firePropertyChange( "selected", new Boolean( !this.selected ), new Boolean
( this.selected ) );
  public void actionPerformed( ActionEvent e )
    Object source = e.getSource( );
    if( source instanceof AbstractButton )
      AbstractButton button = (AbstractButton) source;
      setSelected( button.isSelected( ) );

This classes could be used adding a setToggleAction method to JToggleButton and
(Review ID: 111728)

EVALUATION Because this bug was filed much earlier than 4491747, I'm going to close 4491747 as a duplicate of this but fix all the remaining issues from 4491747 in this bug. Here's the list of things that are going to change: Action will get the new keys: public static final String SELECTED_KEY; public static final String DISPLAYED_MNEMONIC_INDEX_KEY; public static final String LARGE_ICON_KEY; SELECTED_KEY will be useful for togglebutton, radiobutton, checkbox, checkboxmenuitem and radiobuttonmenuitem. If the selected state of the button changes the selected property of the Action will be updated. Similarly if the SELECTED_KEY property of the Action changes the button will update it's state appropriately. DISPLAYED_MNEMONIC_INDEX_KEY name describes what it does;) LARGE_ICON_KEY will be used by all non-menuitem buttons. If LARGE_ICON_KEY is non-null it's value will be used as the icon, if it's null the icon from SMALL_ICON_KEY will be used. The previously undocumented client property 'hideActionText' will now be a public property (AbstractButton will have a set/getter for it). And changes to the property (or client property) will be immediate. The system property swing.actions.reconfigureOnNull will be provided so that if true a 'null' property name will result in the component resetting all interested properties. Finally, all of this will be documented in Action:)

WORK AROUND Name: krC82822 Date: 11/02/2000 The only possible workaround is manual synchronization, as should be done with buttons if Action didn't exist (Review ID: 111728) ======================================================================

EVALUATION We should do this, but we need to figure out an flexible solution for all actions and containers. --- There are a lot of good ideas here. First I was using 4629461 to drive this work in tiger but I'll close that as a duplicate of this one. ###@###.### 2002-05-30 -- This one may require API changes which we cannot do for tiger at this point. We agree that this is an important feature but there is still some discussion on the correct approach. One approach is that we add new classes which represent toggles. Another approach is that the toggles are stored as properties on the Action. ###@###.### 2003-12-08