javax.swing
Interface Action

All Superinterfaces:
ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener , EventListener sample code for java.util.EventListener definition code for java.util.EventListener
All Known Implementing Classes:
AbstractAction sample code for javax.swing.AbstractAction definition code for javax.swing.AbstractAction , BasicDesktopPaneUI.CloseAction sample code for javax.swing.plaf.basic.BasicDesktopPaneUI.CloseAction definition code for javax.swing.plaf.basic.BasicDesktopPaneUI.CloseAction , BasicDesktopPaneUI.MaximizeAction sample code for javax.swing.plaf.basic.BasicDesktopPaneUI.MaximizeAction definition code for javax.swing.plaf.basic.BasicDesktopPaneUI.MaximizeAction , BasicDesktopPaneUI.MinimizeAction sample code for javax.swing.plaf.basic.BasicDesktopPaneUI.MinimizeAction definition code for javax.swing.plaf.basic.BasicDesktopPaneUI.MinimizeAction , BasicDesktopPaneUI.NavigateAction sample code for javax.swing.plaf.basic.BasicDesktopPaneUI.NavigateAction definition code for javax.swing.plaf.basic.BasicDesktopPaneUI.NavigateAction , BasicDesktopPaneUI.OpenAction sample code for javax.swing.plaf.basic.BasicDesktopPaneUI.OpenAction definition code for javax.swing.plaf.basic.BasicDesktopPaneUI.OpenAction , BasicFileChooserUI.ApproveSelectionAction sample code for javax.swing.plaf.basic.BasicFileChooserUI.ApproveSelectionAction definition code for javax.swing.plaf.basic.BasicFileChooserUI.ApproveSelectionAction , BasicFileChooserUI.CancelSelectionAction sample code for javax.swing.plaf.basic.BasicFileChooserUI.CancelSelectionAction definition code for javax.swing.plaf.basic.BasicFileChooserUI.CancelSelectionAction , BasicFileChooserUI.ChangeToParentDirectoryAction sample code for javax.swing.plaf.basic.BasicFileChooserUI.ChangeToParentDirectoryAction definition code for javax.swing.plaf.basic.BasicFileChooserUI.ChangeToParentDirectoryAction , BasicFileChooserUI.GoHomeAction sample code for javax.swing.plaf.basic.BasicFileChooserUI.GoHomeAction definition code for javax.swing.plaf.basic.BasicFileChooserUI.GoHomeAction , BasicFileChooserUI.NewFolderAction sample code for javax.swing.plaf.basic.BasicFileChooserUI.NewFolderAction definition code for javax.swing.plaf.basic.BasicFileChooserUI.NewFolderAction , BasicFileChooserUI.UpdateAction sample code for javax.swing.plaf.basic.BasicFileChooserUI.UpdateAction definition code for javax.swing.plaf.basic.BasicFileChooserUI.UpdateAction , BasicInternalFrameTitlePane.CloseAction sample code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.CloseAction definition code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.CloseAction , BasicInternalFrameTitlePane.IconifyAction sample code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.IconifyAction definition code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.IconifyAction , BasicInternalFrameTitlePane.MaximizeAction sample code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction definition code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction , BasicInternalFrameTitlePane.MoveAction sample code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.MoveAction definition code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.MoveAction , BasicInternalFrameTitlePane.RestoreAction sample code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.RestoreAction definition code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.RestoreAction , BasicInternalFrameTitlePane.SizeAction sample code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.SizeAction definition code for javax.swing.plaf.basic.BasicInternalFrameTitlePane.SizeAction , BasicSliderUI.ActionScroller sample code for javax.swing.plaf.basic.BasicSliderUI.ActionScroller definition code for javax.swing.plaf.basic.BasicSliderUI.ActionScroller , BasicTreeUI.TreeCancelEditingAction sample code for javax.swing.plaf.basic.BasicTreeUI.TreeCancelEditingAction definition code for javax.swing.plaf.basic.BasicTreeUI.TreeCancelEditingAction , BasicTreeUI.TreeHomeAction sample code for javax.swing.plaf.basic.BasicTreeUI.TreeHomeAction definition code for javax.swing.plaf.basic.BasicTreeUI.TreeHomeAction , BasicTreeUI.TreeIncrementAction sample code for javax.swing.plaf.basic.BasicTreeUI.TreeIncrementAction definition code for javax.swing.plaf.basic.BasicTreeUI.TreeIncrementAction , BasicTreeUI.TreePageAction sample code for javax.swing.plaf.basic.BasicTreeUI.TreePageAction definition code for javax.swing.plaf.basic.BasicTreeUI.TreePageAction , BasicTreeUI.TreeToggleAction sample code for javax.swing.plaf.basic.BasicTreeUI.TreeToggleAction definition code for javax.swing.plaf.basic.BasicTreeUI.TreeToggleAction , BasicTreeUI.TreeTraverseAction sample code for javax.swing.plaf.basic.BasicTreeUI.TreeTraverseAction definition code for javax.swing.plaf.basic.BasicTreeUI.TreeTraverseAction , DefaultEditorKit.BeepAction sample code for javax.swing.text.DefaultEditorKit.BeepAction definition code for javax.swing.text.DefaultEditorKit.BeepAction , DefaultEditorKit.CopyAction sample code for javax.swing.text.DefaultEditorKit.CopyAction definition code for javax.swing.text.DefaultEditorKit.CopyAction , DefaultEditorKit.CutAction sample code for javax.swing.text.DefaultEditorKit.CutAction definition code for javax.swing.text.DefaultEditorKit.CutAction , DefaultEditorKit.DefaultKeyTypedAction sample code for javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction definition code for javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction , DefaultEditorKit.InsertBreakAction sample code for javax.swing.text.DefaultEditorKit.InsertBreakAction definition code for javax.swing.text.DefaultEditorKit.InsertBreakAction , DefaultEditorKit.InsertContentAction sample code for javax.swing.text.DefaultEditorKit.InsertContentAction definition code for javax.swing.text.DefaultEditorKit.InsertContentAction , DefaultEditorKit.InsertTabAction sample code for javax.swing.text.DefaultEditorKit.InsertTabAction definition code for javax.swing.text.DefaultEditorKit.InsertTabAction , DefaultEditorKit.PasteAction sample code for javax.swing.text.DefaultEditorKit.PasteAction definition code for javax.swing.text.DefaultEditorKit.PasteAction , HTMLEditorKit.HTMLTextAction sample code for javax.swing.text.html.HTMLEditorKit.HTMLTextAction definition code for javax.swing.text.html.HTMLEditorKit.HTMLTextAction , HTMLEditorKit.InsertHTMLTextAction sample code for javax.swing.text.html.HTMLEditorKit.InsertHTMLTextAction definition code for javax.swing.text.html.HTMLEditorKit.InsertHTMLTextAction , MetalFileChooserUI.DirectoryComboBoxAction sample code for javax.swing.plaf.metal.MetalFileChooserUI.DirectoryComboBoxAction definition code for javax.swing.plaf.metal.MetalFileChooserUI.DirectoryComboBoxAction , StyledEditorKit.AlignmentAction sample code for javax.swing.text.StyledEditorKit.AlignmentAction definition code for javax.swing.text.StyledEditorKit.AlignmentAction , StyledEditorKit.BoldAction sample code for javax.swing.text.StyledEditorKit.BoldAction definition code for javax.swing.text.StyledEditorKit.BoldAction , StyledEditorKit.FontFamilyAction sample code for javax.swing.text.StyledEditorKit.FontFamilyAction definition code for javax.swing.text.StyledEditorKit.FontFamilyAction , StyledEditorKit.FontSizeAction sample code for javax.swing.text.StyledEditorKit.FontSizeAction definition code for javax.swing.text.StyledEditorKit.FontSizeAction , StyledEditorKit.ForegroundAction sample code for javax.swing.text.StyledEditorKit.ForegroundAction definition code for javax.swing.text.StyledEditorKit.ForegroundAction , StyledEditorKit.ItalicAction sample code for javax.swing.text.StyledEditorKit.ItalicAction definition code for javax.swing.text.StyledEditorKit.ItalicAction , StyledEditorKit.StyledTextAction sample code for javax.swing.text.StyledEditorKit.StyledTextAction definition code for javax.swing.text.StyledEditorKit.StyledTextAction , StyledEditorKit.UnderlineAction sample code for javax.swing.text.StyledEditorKit.UnderlineAction definition code for javax.swing.text.StyledEditorKit.UnderlineAction , TextAction sample code for javax.swing.text.TextAction definition code for javax.swing.text.TextAction

public interface Action
extends ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener

The Action interface provides a useful extension to the ActionListener interface in cases where the same functionality may be accessed by several controls.

In addition to the actionPerformed method defined by the ActionListener interface, this interface allows the application to define, in a single place:

Certain containers, including menus and tool bars, know how to add an Action object. When an Action object is added to such a container, the container:
  1. Creates a component that is appropriate for that container (a tool bar creates a button component, for example).
  2. Gets the appropriate property(s) from the Action object to customize the component (for example, the icon image and flyover text).
  3. Checks the initial state of the Action object to determine if it is enabled or disabled, and renders the component in the appropriate fashion.
  4. Registers a listener with the Action object so that is notified of state changes. When the Action object changes from enabled to disabled, or back, the container makes the appropriate revisions to the event-generation mechanisms and renders the component accordingly.
For example, both a menu item and a toolbar button could access a Cut action object. The text associated with the object is specified as "Cut", and an image depicting a pair of scissors is specified as its icon. The Cut action-object can then be added to a menu and to a tool bar. Each container does the appropriate things with the object, and invokes its actionPerformed method when the component associated with it is activated. The application can then disable or enable the application object without worrying about what user-interface components are connected to it.

This interface can be added to an existing class or used to create an adapter (typically, by subclassing AbstractAction). The Action object can then be added to multiple Action-aware containers and connected to Action-capable components. The GUI controls can then be activated or deactivated all at once by invoking the Action object's setEnabled method.

Note that Action implementations tend to be more expensive in terms of storage than a typical ActionListener, which does not offer the benefits of centralized control of functionality and broadcast of property changes. For this reason, you should take care to only use Actions where their benefits are desired, and use simple ActionListeners elsewhere.

See Also:
AbstractAction sample code for javax.swing.AbstractAction definition code for javax.swing.AbstractAction

Field Summary
static String sample code for java.lang.String definition code for java.lang.String ACCELERATOR_KEY sample code for javax.swing.Action.ACCELERATOR_KEY definition code for javax.swing.Action.ACCELERATOR_KEY
          The key used for storing a KeyStroke to be used as the accelerator for the action.
static String sample code for java.lang.String definition code for java.lang.String ACTION_COMMAND_KEY sample code for javax.swing.Action.ACTION_COMMAND_KEY definition code for javax.swing.Action.ACTION_COMMAND_KEY
          The key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.
static String sample code for java.lang.String definition code for java.lang.String DEFAULT sample code for javax.swing.Action.DEFAULT definition code for javax.swing.Action.DEFAULT
          Not currently used.
static String sample code for java.lang.String definition code for java.lang.String LONG_DESCRIPTION sample code for javax.swing.Action.LONG_DESCRIPTION definition code for javax.swing.Action.LONG_DESCRIPTION
          The key used for storing a longer String description for the action, could be used for context-sensitive help.
static String sample code for java.lang.String definition code for java.lang.String MNEMONIC_KEY sample code for javax.swing.Action.MNEMONIC_KEY definition code for javax.swing.Action.MNEMONIC_KEY
          The key used for storing a KeyEvent to be used as the mnemonic for the action.
static String sample code for java.lang.String definition code for java.lang.String NAME sample code for javax.swing.Action.NAME definition code for javax.swing.Action.NAME
          The key used for storing the String name for the action, used for a menu or button.
static String sample code for java.lang.String definition code for java.lang.String SHORT_DESCRIPTION sample code for javax.swing.Action.SHORT_DESCRIPTION definition code for javax.swing.Action.SHORT_DESCRIPTION
          The key used for storing a short String description for the action, used for tooltip text.
static String sample code for java.lang.String definition code for java.lang.String SMALL_ICON sample code for javax.swing.Action.SMALL_ICON definition code for javax.swing.Action.SMALL_ICON
          The key used for storing a small Icon, such as ImageIcon, for the action, used for toolbar buttons.
 
Method Summary
 void addPropertyChangeListener sample code for javax.swing.Action.addPropertyChangeListener(java.beans.PropertyChangeListener) definition code for javax.swing.Action.addPropertyChangeListener(java.beans.PropertyChangeListener) (PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  listener)
          Adds a PropertyChange listener.
 Object sample code for java.lang.Object definition code for java.lang.Object getValue sample code for javax.swing.Action.getValue(java.lang.String) definition code for javax.swing.Action.getValue(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  key)
          Gets one of this object's properties using the associated key.
 boolean isEnabled sample code for javax.swing.Action.isEnabled() definition code for javax.swing.Action.isEnabled() ()
          Returns the enabled state of the Action.
 void putValue sample code for javax.swing.Action.putValue(java.lang.String, java.lang.Object) definition code for javax.swing.Action.putValue(java.lang.String, java.lang.Object) (String sample code for java.lang.String definition code for java.lang.String  key, Object sample code for java.lang.Object definition code for java.lang.Object  value)
          Sets one of this object's properties using the associated key.
 void removePropertyChangeListener sample code for javax.swing.Action.removePropertyChangeListener(java.beans.PropertyChangeListener) definition code for javax.swing.Action.removePropertyChangeListener(java.beans.PropertyChangeListener) (PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  listener)
          Removes a PropertyChange listener.
 void setEnabled sample code for javax.swing.Action.setEnabled(boolean) definition code for javax.swing.Action.setEnabled(boolean) (boolean b)
          Sets the enabled state of the Action.
 
Methods inherited from interface java.awt.event.ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener
actionPerformed sample code for java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent) definition code for java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent)
 

Field Detail

DEFAULT sample code for javax.swing.Action.DEFAULT

static final String sample code for java.lang.String definition code for java.lang.String  DEFAULT
Not currently used.

See Also:
Constant Field Values

NAME sample code for javax.swing.Action.NAME

static final String sample code for java.lang.String definition code for java.lang.String  NAME
The key used for storing the String name for the action, used for a menu or button.

See Also:
Constant Field Values

SHORT_DESCRIPTION sample code for javax.swing.Action.SHORT_DESCRIPTION

static final String sample code for java.lang.String definition code for java.lang.String  SHORT_DESCRIPTION
The key used for storing a short String description for the action, used for tooltip text.

See Also:
Constant Field Values

LONG_DESCRIPTION sample code for javax.swing.Action.LONG_DESCRIPTION

static final String sample code for java.lang.String definition code for java.lang.String  LONG_DESCRIPTION
The key used for storing a longer String description for the action, could be used for context-sensitive help.

See Also:
Constant Field Values

SMALL_ICON sample code for javax.swing.Action.SMALL_ICON

static final String sample code for java.lang.String definition code for java.lang.String  SMALL_ICON
The key used for storing a small Icon, such as ImageIcon, for the action, used for toolbar buttons.

See Also:
Constant Field Values

ACTION_COMMAND_KEY sample code for javax.swing.Action.ACTION_COMMAND_KEY

static final String sample code for java.lang.String definition code for java.lang.String  ACTION_COMMAND_KEY
The key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.

See Also:
Constant Field Values

ACCELERATOR_KEY sample code for javax.swing.Action.ACCELERATOR_KEY

static final String sample code for java.lang.String definition code for java.lang.String  ACCELERATOR_KEY
The key used for storing a KeyStroke to be used as the accelerator for the action.

Since:
1.3
See Also:
Constant Field Values

MNEMONIC_KEY sample code for javax.swing.Action.MNEMONIC_KEY

static final String sample code for java.lang.String definition code for java.lang.String  MNEMONIC_KEY
The key used for storing a KeyEvent to be used as the mnemonic for the action.

Since:
1.3
See Also:
Constant Field Values
Method Detail

getValue sample code for javax.swing.Action.getValue(java.lang.String) definition code for javax.swing.Action.getValue(java.lang.String)

Object sample code for java.lang.Object definition code for java.lang.Object  getValue(String sample code for java.lang.String definition code for java.lang.String  key)
Gets one of this object's properties using the associated key.

See Also:
putValue(java.lang.String, java.lang.Object) sample code for javax.swing.Action.putValue(java.lang.String, java.lang.Object) definition code for javax.swing.Action.putValue(java.lang.String, java.lang.Object)

putValue sample code for javax.swing.Action.putValue(java.lang.String, java.lang.Object) definition code for javax.swing.Action.putValue(java.lang.String, java.lang.Object)

void putValue(String sample code for java.lang.String definition code for java.lang.String  key,
              Object sample code for java.lang.Object definition code for java.lang.Object  value)
Sets one of this object's properties using the associated key. If the value has changed, a PropertyChangeEvent is sent to listeners.

Parameters:
key - a String containing the key
value - an Object value

setEnabled sample code for javax.swing.Action.setEnabled(boolean) definition code for javax.swing.Action.setEnabled(boolean)

void setEnabled(boolean b)
Sets the enabled state of the Action. When enabled, any component associated with this object is active and able to fire this object's actionPerformed method. If the value has changed, a PropertyChangeEvent is sent to listeners.

Parameters:
b - true to enable this Action, false to disable it

isEnabled sample code for javax.swing.Action.isEnabled() definition code for javax.swing.Action.isEnabled()

boolean isEnabled()
Returns the enabled state of the Action. When enabled, any component associated with this object is active and able to fire this object's actionPerformed method.

Returns:
true if this Action is enabled

addPropertyChangeListener sample code for javax.swing.Action.addPropertyChangeListener(java.beans.PropertyChangeListener) definition code for javax.swing.Action.addPropertyChangeListener(java.beans.PropertyChangeListener)

void addPropertyChangeListener(PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  listener)
Adds a PropertyChange listener. Containers and attached components use these methods to register interest in this Action object. When its enabled state or other property changes, the registered listeners are informed of the change.

Parameters:
listener - a PropertyChangeListener object

removePropertyChangeListener sample code for javax.swing.Action.removePropertyChangeListener(java.beans.PropertyChangeListener) definition code for javax.swing.Action.removePropertyChangeListener(java.beans.PropertyChangeListener)

void removePropertyChangeListener(PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  listener)
Removes a PropertyChange listener.

Parameters:
listener - a PropertyChangeListener object
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener) sample code for javax.swing.Action.addPropertyChangeListener(java.beans.PropertyChangeListener) definition code for javax.swing.Action.addPropertyChangeListener(java.beans.PropertyChangeListener)