Module java.desktop
Package javax.swing

Interface Action

    • Field Detail

      • NAME

        static final 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

        static final 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

        static final 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

        static final String SMALL_ICON
        The key used for storing a small Icon, such as ImageIcon. This is typically used with menus such as JMenuItem.

        If the same Action is used with menus and buttons you'll typically specify both a SMALL_ICON and a LARGE_ICON_KEY. The menu will use the SMALL_ICON and the button will use the LARGE_ICON_KEY.

        See Also:
        Constant Field Values
      • ACTION_COMMAND_KEY

        static final 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

        static final 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

        static final String MNEMONIC_KEY
        The key used for storing an Integer that corresponds to one of the KeyEvent key codes. The value is commonly used to specify a mnemonic. For example: myAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A) sets the mnemonic of myAction to 'a', while myAction.putValue(Action.MNEMONIC_KEY, KeyEvent.getExtendedKeyCodeForChar('?')) sets the mnemonic of myAction to Cyrillic letter "Ef".
        Since:
        1.3
        See Also:
        Constant Field Values
      • SELECTED_KEY

        static final String SELECTED_KEY
        The key used for storing a Boolean that corresponds to the selected state. This is typically used only for components that have a meaningful selection state. For example, JRadioButton and JCheckBox make use of this but instances of JMenu don't.

        This property differs from the others in that it is both read by the component and set by the component. For example, if an Action is attached to a JCheckBox the selected state of the JCheckBox will be set from that of the Action. If the user clicks on the JCheckBox the selected state of the JCheckBox and the Action will both be updated.

        Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing Actions.

        Since:
        1.6
        See Also:
        Constant Field Values
      • DISPLAYED_MNEMONIC_INDEX_KEY

        static final String DISPLAYED_MNEMONIC_INDEX_KEY
        The key used for storing an Integer that corresponds to the index in the text (identified by the NAME property) that the decoration for a mnemonic should be rendered at. If the value of this property is greater than or equal to the length of the text, it will treated as -1.

        Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing Actions.

        Since:
        1.6
        See Also:
        AbstractButton.setDisplayedMnemonicIndex(int), Constant Field Values
      • LARGE_ICON_KEY

        static final String LARGE_ICON_KEY
        The key used for storing an Icon. This is typically used by buttons, such as JButton and JToggleButton.

        If the same Action is used with menus and buttons you'll typically specify both a SMALL_ICON and a LARGE_ICON_KEY. The menu will use the SMALL_ICON and the button the LARGE_ICON_KEY.

        Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing Actions.

        Since:
        1.6
        See Also:
        Constant Field Values
    • Method Detail

      • putValue

        void putValue​(String key,
                      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

        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
        See Also:
        accept(java.lang.Object)
      • 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
        See Also:
        accept(java.lang.Object)
      • accept

        default boolean accept​(Object sender)
        Determines whether the action should be performed with the specified sender object. The sender can be null. The method must return false if the action is disabled.

        Parameters:
        sender - the object to check, can be null
        Returns:
        true if the action should be performed with the sender object, must be false if the action is disabled.
        See Also:
        isEnabled(), setEnabled(boolean)
      • addPropertyChangeListener

        void addPropertyChangeListener​(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