Box, Boxlayout problem

Box, Boxlayout problem

Post by Sean Ander » Sun, 15 May 2005 10:35:45

here is the code

Box form = Box.createVerticalBox();


// Put form fields here

for (int a=0; a < 6; a++){

JL[a].setAlignmentX(0); //inserted for the hell-of-it to see if it
would change anything, supposed to default left


if (a==0) {form.add(Title = new JTextField(30));
Title.setMaximumSize(new Dimension (325,20)); }

if (a==1) {form.add(Author = new JTextField(25));
Author.setMaximumSize(new Dimension (300,20));}

if (a==2) {form.add(Category = new JComboBox());
Category.setEditable(true); Category.setMaximumSize(new Dimension

if (a==3) {form.add(Code = new JTextField(20)); Code.setMaximumSize(new
Dimension (200,20));}

if (a==4) {form.add(Publisher = new JComboBox());
Publisher.setEditable(true); Publisher.setMaximumSize(new Dimension

if (a==5) {form.add(Year = new JTextField(10)); Year.setMaximumSize(new
Dimension (100,20));}


when the app runs the JTextFields and JLabels are all in the center!? I
have done this in a JFrame and this worked fine as everything aligned to the
left. I have checked through several references/doc and none of them get
detailed enough. What am I doing wrong?


Box, Boxlayout problem

Post by Menno Hols » Sun, 15 May 2005 21:46:57

Nothing. A BoxLayout lays out the items in the direction you are not
lay-outing in centered. It is part of the behaviour of the manager. It
should be documented in the layout manager or under Box.
Groeten van/regards



Box, Boxlayout problem

Post by Sean Ander » Sun, 15 May 2005 22:55:43

you said"A BoxLayout lays out the items in the direction you are not
lay-outing in centered."

what ?

I have used this layout before and everything aligned left when I set the
max size but this was in a JFrame contentPane
not a JPanel. this is from the BoxLayout tut:

" The X alignments affect not only the components' positions relative to
each other, but also the location of the components (as a group) within
their container. The following figures illustrate alignment of components
that have restricted maximum widths."

it goes on to show compenents aligned left (0.0, LEFT_ALIGNMENT) the way I'm
trying to align my components:

" In the first figure, all three components have an X alignment of 0.0
(Component.LEFT_ALIGNMENT). This means that the components' left sides
should be aligned. Furthermore, it means that all three components are
positioned as far left in their container as possible. "

I have set my X Alignment for most components and they are all still
centered in the Panel!! I know I'm missing something simple?!



Box, Boxlayout problem

Post by Sean Ander » Mon, 16 May 2005 09:36:29

As I see from reading closer (eyes squinted) I see that ALL components need
to have their setAlignmentX set to LEFT not just some or most. Works great