JDK-4765360 : JMenuItem.add(Action) does not handle Action.SHORT_DESCRIPTION properly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2002-10-18
  • Updated: 2005-08-16
  • Resolved: 2005-08-16
Related Reports
Duplicate :  
Description
Name: sv35042			Date: 10/18/2002


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)


FULL OPERATING SYSTEM VERSION :
Suse 8.0, Kernel 2.4.18

ADDITIONAL OPERATING SYSTEMS :
Windows XP.



EXTRA RELEVANT SYSTEM CONFIGURATION :
Tested against JDK 1.4.0_01

A DESCRIPTION OF THE PROBLEM :
If I add a Action to a JMenu with jmenu.add(new
AbstractAction() {...}); and I change the properties of the
action object, only the Action.NAME and Action.MNEMONIC_KEY
property is changed correctly. The property
Action.SHORT_DESCRIPTION does not change. Especially this is
annoying on I18N programs which fetch their property values
from a resource bundle.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Build a action which bounds to some changing property,
e.g. the change of the "locale" property on some "property
provider"
2.Change the property on the "property provider"
3.Action.NAME does change, Action.SHORT_DESCRIPTION does not

EXPECTED VERSUS ACTUAL BEHAVIOR :
The tooltip should change accordingly.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Locale;
import javax.swing.*;

/**
 * TestFrame to reproduce the unchanging Action.SHORT_DESCRIPTION property.
 *
 *
 * Created: Tue Aug 13 13:49:58 2002
 *
 * @author <a href="mailto:###@###.###">Frank Meissner</a>
 */

public class TestFrame extends JFrame {

  public  TestFrame() {
    super("Action Test");
    setSize(300, 300);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {System.exit(0);}
        public void windowOpened(WindowEvent e) {}
      });
    setJMenuBar(createMenu());
    getContentPane().add(new JButton(getTestAction(getJMenuBar())));

  }

  public static void main(String[] args) {

    TestFrame f = new TestFrame();
    f.show();
  }

  protected JMenuBar createMenu() {
    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("File");
    final JComponent localeProvider = mb;
    menu.add(new AbstractAction("Exit") {
        public void actionPerformed(ActionEvent e) {
          System.exit(0);
        }
      });
    menu.add(new AbstractAction("English") {
        public void actionPerformed(ActionEvent e) {
          localeProvider.setLocale(Locale.ENGLISH);
        }
      });
    menu.add(new AbstractAction("Deutsch") {
        public void actionPerformed(ActionEvent e) {
          localeProvider.setLocale(Locale.GERMAN);
        }
      });
    menu.add(getTestAction(localeProvider));

    mb.add(menu);
    return mb;
  }

  TestAction ta = null;
  TestAction getTestAction(JComponent localeProvider) {
    if (ta == null) {
      ta = new TestAction(localeProvider);
    }
    return ta;
  }


  public class TestAction extends AbstractAction {
    int count = 0;
    public TestAction(JComponent localeProvider) {
      // initial:
      putValue(Action.NAME,
               String.valueOf(count));
      putValue(Action.SHORT_DESCRIPTION,
               "Tooltip is " + String.valueOf(count));
      localeProvider.addPropertyChangeListener("locale",
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            // on a property change event:
            count ++;
            putValue(Action.NAME, String.valueOf(count));
            putValue(Action.SHORT_DESCRIPTION,
                     "Tooltip is " + String.valueOf(count));
          }
        });
    }
    public void actionPerformed(ActionEvent event) {
      System.out.println("count is " + count);
    }

  }
} // TestFrame

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
none known
(Review ID: 160707) 
======================================================================

Comments
EVALUATION This has been address as part of 4626632, closing as a duplicate.
16-08-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
02-10-2004

EVALUATION Yep, SHORT_DESCRIPTION is not updated. ###@###.### 2002-10-18
18-10-2002