-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0
-
x86
-
linux
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)
======================================================================
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)
======================================================================
- duplicates
-
JDK-4626632 Various containers for Action throw NPE when PropChgEvent has null newValue
-
- Resolved
-