-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0
-
generic
-
generic
Name: krC82822 Date: 12/16/2000
16 Dec 2000, eval1127@eng -- reproducible under 1.3.0 and 1.4beta45.
Seems related to previously-closed bug # 4106486.
---------------
java version "1.4.0beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b45)
Java HotSpot(TM) Client VM (build 1.4beta-B45, mixed mode)
(submitted against Solaris)
java version "1.3.0"
Java(TM) Runtime Environment, Standard Edition (build 1.3.0-RC)
Java HotSpot(TM) Client VM (build 1.3.0-RC, mixed mode)
Reproducing the error :
1. create a JToolBar
2. add an Action which has an Icon and a Text to this tool bar
3. make it visible
-> only the icon will be shown (o.k.)
4. change the actions text
-> the icon AND the text is shown in the tool bar now (error)
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
public static void main(String[] arg) {
new Test();
}
public Test() {
JToolBar tb = new JToolBar();
tb.add(new MyAction());
getContentPane().add(tb);
pack();
setVisible(true);
}
}
class MyAction extends AbstractAction {
MyAction() {
// an icon form somwhere...
putValue(Action.SMALL_ICON, new ImageIcon(ClassLoader.getSystemResource(
"toolbarButtonGraphics/general/Add16.gif")));
putValue(Action.NAME, "Old Name");
}
public void actionPerformed(ActionEvent ev) {
putValue(Action.NAME, "New Name");
}
}
------------
Some investigations have been done:
1. JToolbar uses createActionComponent(Action a) to create a button out of a
given action, here, the "hideActionText" property is set to TRUE if an icon is
given. This results in a correct look of the component for the first time
showing (only the icon is shown if icon != null)
2. In JToolbar#createActionComponent(Action a), a PropertyChangeListener is
added to the button created. This change listener comes from AbstractButtons
property change listener factory and returns and object of type:
private static class ButtonActionPropertyChangeListener extends
AbstractActionPropertyChangeListener {
ButtonActionPropertyChangeListener(AbstractButton b, Action a) {
super(b, a);
}
public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName();
AbstractButton button = (AbstractButton)getTarget();
if (button == null) { //WeakRef GC'ed in 1.2
Action action = (Action)e.getSource();
action.removePropertyChangeListener(this);
} else {
if (e.getPropertyName().equals(Action.NAME)) {
String text = (String) e.getNewValue();
button.setText(text);
button.repaint();
} else {
....
}
}
}
As one can see, if the name of the action changes, the name is set as the
buttons text without checking the "hideActionText" property. This results in the
erroneous behavior.
(Review ID: 108917)
======================================================================
- duplicates
-
JDK-4391622 text appears in toolbar button after Action.putValue(Action.NAME, ...)
-
- Resolved
-