-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b22
-
x86
-
windows_xp
-
Not verified
FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
BasicSpinnerUI changes the horizontalAlignment value of the new Editor instance specifically to be that of the UIManager's "Spinner.editorAlignment" value. This occurs when setting the new Editor on the JSpinner using JSpinner.setEditor(JComponent editor).
Given that setEditor() makes no claims to alter the horizontalAlignment of the underlying editor's components, and generally has no right to do so, it should not be doing this. This defect is manifested in that previously unobserved text alignments are shown in JSpinner's when running under Java 1.6
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and execute the provided source code below. This very simple example sets the horizontal text alignment on the JFormattedTextField within the DefaultEditor to LEFT, prior to setting the JSpinner's editor using setEditor(JComponent editor).
Under 1.5 and prior versions, the alignment of the text within this JSpinner can be seen to be LEFT aligned. Under Java 1.6, the text is RIGHT aligned (or more specifically TRAILING aligned).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A small frame should be displayed, with a single JSpinner component, containing the numeric value 0, left aligned. This is evidenced under Java 1.5 and Java 1.4
ACTUAL -
Under Java 1.6, the above code shows a small frame containing a single JSpinner component with the numeric value 0, RIGHT aligned. (Upon debugging, it can be seen that the alignment value is in fact altered to SwingConstants.TRAILING, so the value will in fact only be right aligned if tested in a left to right language environment.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class SpinnerBug
{
public static void main(String[] args)
{
JSpinner s = new JSpinner();
JSpinner.DefaultEditor customEditor = new JSpinner.DefaultEditor(s);
customEditor.getTextField().setHorizontalAlignment(SwingUtilities.LEFT);
s.setEditor(customEditor);
JFrame f = new JFrame();
f.getContentPane().add(s);
f.setSize(200, 200);
f.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Set the alignment on the editor component AFTER setting the JSpinner's editor. For example, inserting the line:
customEditor.getTextField().setHorizontalAlignment(SwingUtilities.LEFT);
after the call: s.setEditor(customEditor);
will cause this to function correctly.
Release Regression From : 5.0u11
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
BasicSpinnerUI changes the horizontalAlignment value of the new Editor instance specifically to be that of the UIManager's "Spinner.editorAlignment" value. This occurs when setting the new Editor on the JSpinner using JSpinner.setEditor(JComponent editor).
Given that setEditor() makes no claims to alter the horizontalAlignment of the underlying editor's components, and generally has no right to do so, it should not be doing this. This defect is manifested in that previously unobserved text alignments are shown in JSpinner's when running under Java 1.6
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and execute the provided source code below. This very simple example sets the horizontal text alignment on the JFormattedTextField within the DefaultEditor to LEFT, prior to setting the JSpinner's editor using setEditor(JComponent editor).
Under 1.5 and prior versions, the alignment of the text within this JSpinner can be seen to be LEFT aligned. Under Java 1.6, the text is RIGHT aligned (or more specifically TRAILING aligned).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A small frame should be displayed, with a single JSpinner component, containing the numeric value 0, left aligned. This is evidenced under Java 1.5 and Java 1.4
ACTUAL -
Under Java 1.6, the above code shows a small frame containing a single JSpinner component with the numeric value 0, RIGHT aligned. (Upon debugging, it can be seen that the alignment value is in fact altered to SwingConstants.TRAILING, so the value will in fact only be right aligned if tested in a left to right language environment.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class SpinnerBug
{
public static void main(String[] args)
{
JSpinner s = new JSpinner();
JSpinner.DefaultEditor customEditor = new JSpinner.DefaultEditor(s);
customEditor.getTextField().setHorizontalAlignment(SwingUtilities.LEFT);
s.setEditor(customEditor);
JFrame f = new JFrame();
f.getContentPane().add(s);
f.setSize(200, 200);
f.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Set the alignment on the editor component AFTER setting the JSpinner's editor. For example, inserting the line:
customEditor.getTextField().setHorizontalAlignment(SwingUtilities.LEFT);
after the call: s.setEditor(customEditor);
will cause this to function correctly.
Release Regression From : 5.0u11
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
- relates to
-
JDK-6349138 JSpinner component shows up differently in GTK L&F functionality Also differing
- Resolved