<Swing Dev> Review Request for Bug 8146320 JTextField ignores setPreferredSize when having columns
Andrej Golovnin
andrej.golovnin at gmail.com
Thu Jan 21 11:19:12 UTC 2016
Hi Perm,
I'm sorry, my mistake. To see the difference you must run the example
with JDK 8, e.g. without your patch. The example contains two fields
"jdk8" and "jdk9". The "jdk9" field simulates the behaviour of
JTextField with your patch. Both fields "jdk8" and "jdk9" should have
the same size on the screen. But after your patch the "jdk9" field is
only 10 pixel wide.
Suppose developers had following use case in the past:
We need a field which should be 10 columns wide and 20 pixels high.
The field must be inside of a panel with BoxLayout and laid out
horizontally from left to right.
What did they done in such situations:
JTextField field = new JTextField(10):
field.setPreferredSize(new Dimension(10, 20)); // The real width will
be calculated by JTextField using the number of columns.
JPanel content = new JPanel();
BoxLayout layout = new BoxLayout(content, BoxLayout.X_AXIS);
content.setLayout(layout);
content.add(field);
This code implements the use case above (from JavaDocs of BoxLayout:
BoxLayout attempts to arrange components at their preferred widths
(for horizontal layout) or heights (for vertical layout).). But your
change would break now this implementation. After your change the
field would have only the size of 10 pixels x 20 pixels ant not the
expected 10 columns x 20 pixels.
Best regards,
Andrej Golovnin
More information about the swing-dev
mailing list