-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.4.2
-
Cause Known
-
x86
-
linux
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
A DESCRIPTION OF THE PROBLEM :
BasicSpinnerUI updates the enabled state of all descendants of the editor component to the same state as the spinner. It has no business doing so: The editor may consist of multiple components some of which should be disabled or not depending solely on the editor.
The current implementation makes this impossible because on BasicSpinnerUI installation, editor change, and JSpinner enabled change, all descendants of the editor are set to the same value, override the editor's settings.
If the editor wants to propagate enabled changes to any of its descendants, it can do so on its own. BasicSpinnerUI should just propagate between JSpinner and editor (i.e. root of the hierachy) (and its buttons if any).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute code below. The editor contains an additional button which, in this simplified setting, should always be disabled *no matter whether the JSpinner is or not).
However it is set to enabled on installation (JSpinner.setEditor) by BasicSpinnerUI (see forced stack trace on setEnabled call).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Button remains disabled.
ACTUAL -
Button become enabled.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1064)
at E$1.setEnabled(E.java:20)
at javax.swing.plaf.basic.BasicSpinnerUI.updateEnabledState(BasicSpinnerUI.java:408)
at javax.swing.plaf.basic.BasicSpinnerUI.updateEnabledState(BasicSpinnerUI.java:410)
at javax.swing.plaf.basic.BasicSpinnerUI.updateEnabledState(BasicSpinnerUI.java:396)
at javax.swing.plaf.basic.BasicSpinnerUI.access$300(BasicSpinnerUI.java:33)
at javax.swing.plaf.basic.BasicSpinnerUI$PropertyChangeHandler.propertyChange(BasicSpinnerUI.java:812)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
at javax.swing.JComponent.firePropertyChange(JComponent.java:3822)
at javax.swing.JSpinner.setEditor(JSpinner.java:456)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class E
extends JSpinner.DefaultEditor
{
public E(JSpinner s)
{
super(s);
JButton b = new JButton("Disabled")
{
{
super.setEnabled(false);
}
public void setEnabled(boolean value)
{
Thread.dumpStack();
super.setEnabled(value);
}
};
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(b);
}
public static void main(String[] args)
{
JSpinner s = new JSpinner(new SpinnerListModel(new Object[] { "A", "B", "C" }));
s.setEditor(new E(s));
JFrame f = new JFrame();
f.getContentPane().add(s);
f.setSize(400, 300);
f.show();
}
}
---------- END SOURCE ----------
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
A DESCRIPTION OF THE PROBLEM :
BasicSpinnerUI updates the enabled state of all descendants of the editor component to the same state as the spinner. It has no business doing so: The editor may consist of multiple components some of which should be disabled or not depending solely on the editor.
The current implementation makes this impossible because on BasicSpinnerUI installation, editor change, and JSpinner enabled change, all descendants of the editor are set to the same value, override the editor's settings.
If the editor wants to propagate enabled changes to any of its descendants, it can do so on its own. BasicSpinnerUI should just propagate between JSpinner and editor (i.e. root of the hierachy) (and its buttons if any).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute code below. The editor contains an additional button which, in this simplified setting, should always be disabled *no matter whether the JSpinner is or not).
However it is set to enabled on installation (JSpinner.setEditor) by BasicSpinnerUI (see forced stack trace on setEnabled call).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Button remains disabled.
ACTUAL -
Button become enabled.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1064)
at E$1.setEnabled(E.java:20)
at javax.swing.plaf.basic.BasicSpinnerUI.updateEnabledState(BasicSpinnerUI.java:408)
at javax.swing.plaf.basic.BasicSpinnerUI.updateEnabledState(BasicSpinnerUI.java:410)
at javax.swing.plaf.basic.BasicSpinnerUI.updateEnabledState(BasicSpinnerUI.java:396)
at javax.swing.plaf.basic.BasicSpinnerUI.access$300(BasicSpinnerUI.java:33)
at javax.swing.plaf.basic.BasicSpinnerUI$PropertyChangeHandler.propertyChange(BasicSpinnerUI.java:812)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
at javax.swing.JComponent.firePropertyChange(JComponent.java:3822)
at javax.swing.JSpinner.setEditor(JSpinner.java:456)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class E
extends JSpinner.DefaultEditor
{
public E(JSpinner s)
{
super(s);
JButton b = new JButton("Disabled")
{
{
super.setEnabled(false);
}
public void setEnabled(boolean value)
{
Thread.dumpStack();
super.setEnabled(value);
}
};
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(b);
}
public static void main(String[] args)
{
JSpinner s = new JSpinner(new SpinnerListModel(new Object[] { "A", "B", "C" }));
s.setEditor(new E(s));
JFrame f = new JFrame();
f.getContentPane().add(s);
f.setSize(400, 300);
f.show();
}
}
---------- END SOURCE ----------