Box, Boxlayout problem

Discussion in 'Java' started by Sean Anderson, May 14, 2005.

  1. here is the code

    Box form = Box.createVerticalBox();

    form.setBorder(BorderFactory.createRaisedBevelBorder());




    // 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

    form.add(JL[a]);


    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
    (300,20));}

    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
    (300,20));}

    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?



    Sean
     
    Sean Anderson, May 14, 2005
    #1
    1. Advertising

  2. Sean Anderson wrote:


    > Box form = Box.createVerticalBox();


    > 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?


    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

    Menno
     
    Menno Holscher, May 14, 2005
    #2
    1. Advertising

  3. 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?!

    Sean


    "Menno Holscher" <> wrote in message
    news:d64rp0$6ll$...
    > Sean Anderson wrote:
    >
    >
    > > Box form = Box.createVerticalBox();

    >
    > > 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?

    >
    > 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
    >
    > Menno
     
    Sean Anderson, May 14, 2005
    #3
  4. 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
    now.

    Sean
    "Menno Holscher" <> wrote in message
    news:d64rp0$6ll$...
    > Sean Anderson wrote:
    >
    >
    > > Box form = Box.createVerticalBox();

    >
    > > 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?

    >
    > 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
    >
    > Menno
     
    Sean Anderson, May 15, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Stewart

    BoxLayout bug in 1.5?

    Ryan Stewart, Feb 23, 2005, in forum: Java
    Replies:
    10
    Views:
    4,535
    Ryan Stewart
    Mar 2, 2005
  2. alex_us01
    Replies:
    9
    Views:
    14,736
    Roedy Green
    Oct 1, 2005
  3. Christian Otteneuer

    Alignment in Swing-BoxLayout

    Christian Otteneuer, Jul 8, 2006, in forum: Java
    Replies:
    0
    Views:
    608
    Christian Otteneuer
    Jul 8, 2006
  4. Duane Evenson
    Replies:
    5
    Views:
    1,470
    RedGrittyBrick
    Sep 27, 2007
  5. Aaron Fude

    BoxLayout Woes

    Aaron Fude, Nov 7, 2008, in forum: Java
    Replies:
    7
    Views:
    569
    public boolean
    Nov 12, 2008
Loading...

Share This Page