JDK-4381361 : ACTION_COMMAND_KEY value in Action is ignored
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2000-10-20
  • Updated: 2001-06-14
  • Resolved: 2001-06-14
Related Reports
Duplicate :  
Description

Name: skT45625			Date: 10/20/2000


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


1) Create an Action with one String for the NAME value and another String for
the ACTION_COMMAND_KEY value.
2) Implement the actionPeformed() method in the Action so that it prints out the
action command for the Action.
3) Now create a JMenu and add the Action to it.
4) Observe the action command printed out when the menu item is selected.  The
NAME value for the action is used as the action command instead of the
ACTION_COMMAND_KEY value.

This same behavior was also observed when adding the action to a JToolBar.

Here's some sample code which demonstrates this bug both with a menu and a
toolbar:

--- BEGIN SAMPLE SOURCE CODE ---
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ActionTest extends JFrame {

    public ActionTest() {
        JMenuBar mb= new JMenuBar();
        JMenu m= new JMenu("Test");
        Action a= new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Action command is: " +
                                       e.getActionCommand());
                }
            };
        a.putValue(Action.NAME, "Test Action Bug...");
        a.putValue(Action.ACTION_COMMAND_KEY, "ACTION!");
        m.add(a);
        mb.add(m);
        setJMenuBar(mb);
        JToolBar tb= new JToolBar();
        tb.add(a);
        getContentPane().add(tb, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        ActionTest at= new ActionTest();
        at.setSize(200,100);
        at.setVisible(true);
    }

}
--- END SAMPLE SOURCE CODE ---
(Review ID: 111158) 
======================================================================

Comments
EVALUATION Name: pzR10082 Date: 06/14/2001 This is one of the problems described in bug #4457940. ###@###.### 2001-06-14 ======================================================================
14-06-2001