Results 1 to 10 of 10
  1. #1
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default Vertical box and positioning

    I add buttons, labels and a combobox to a panel.
    I use a vertical box to get it vertical beneath eachother because its a gamepanel with a buttonpanel on the right side.

    The layout is ok, but when i add my combobox the layout changes like you can see on the image.

    An extra vertical box for the combobox doesn't help because it puts the combobox on the right side of the labels.
    Not under them.

    this is the code:
    Java Code:
            verticalBox.add(restartButton);
            verticalBox.add(Box.createVerticalStrut(10));
            verticalBox.add(hoofdMenuButton);
            verticalBox.add(Box.createVerticalStrut(10));
            verticalBox.add(naamLabel);
            verticalBox.add(naamInvoerLabel);
            verticalBox.add(Box.createVerticalStrut(10));
            verticalBox.add(levelLabel);
            verticalBox.add(levelInvoerLabel);
            verticalBox.add(Box.createVerticalStrut(10));
            verticalBox.add(playgroundLabel);
            verticalBox.add(playgroundInvoerLabel);
            verticalBox.add(Box.createVerticalStrut(20));
            verticalBox.add(playgroundComboBox);

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I don't see this picture you refer to.

  3. #3
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Here is the attachment. You can see whats going wrong with the layout.
    A borderlayout within the add doesn't work. I can't seem to get them straight under eachother.
    Attached Thumbnails Attached Thumbnails Vertical box and positioning-verticalbox.png  

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    How exactly do you want it to look? Labels on the left side with buttons on right?

    If that's what you want you can use a horizontal box for each label button pair? Then add that horizontal box to the vertical box. If thats not what you are looking for, please help me understand.

  5. #5
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    I set the widt and height with the following code:

    Java Code:
    Dimension buttonSize = new Dimension(100, 20);
    Dimension comboBoxSize = new Dimension(100, 20);

  6. #6
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    No, like it is now, only straight left beneath eachother.
    So on the postion where the combobox begins.

  7. #7
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    When i comment out, adding the combobox you get a good look of how i want it to be.
    Attached Thumbnails Attached Thumbnails Vertical box and positioning-verticalbox.jpg  
    Last edited by aborgeld; 03-31-2011 at 03:24 PM.

  8. #8
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

  9. #9
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Thanks for the reply, i know the documentation, but the hint helped me a lot.

  10. #10
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    The site was great, it worked and the samples are very good to!

Similar Threads

  1. problem positioning a JPanel in a JScrollPane
    By gib65 in forum AWT / Swing
    Replies: 5
    Last Post: 09-06-2013, 09:27 AM
  2. Positioning println codes to corners
    By javanewby in forum New To Java
    Replies: 2
    Last Post: 09-28-2010, 02:50 PM
  3. Positioning using setBounds
    By thayalan in forum AWT / Swing
    Replies: 4
    Last Post: 04-28-2009, 02:59 AM
  4. I obviously don't understand positioning panels
    By javatard in forum New To Java
    Replies: 2
    Last Post: 12-10-2008, 08:48 AM
  5. panel positioning
    By shwein in forum New To Java
    Replies: 4
    Last Post: 09-09-2008, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •