Results 1 to 10 of 10
Thread: Vertical box and positioning
- 03-31-2011, 02:04 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
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);
- 03-31-2011, 02:06 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I don't see this picture you refer to.
- 03-31-2011, 02:09 PM #3
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
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.
- 03-31-2011, 02:11 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 03-31-2011, 02:16 PM #5
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
I set the widt and height with the following code:
Java Code:Dimension buttonSize = new Dimension(100, 20); Dimension comboBoxSize = new Dimension(100, 20);
- 03-31-2011, 02:19 PM #6
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
No, like it is now, only straight left beneath eachother.
So on the postion where the combobox begins.
- 03-31-2011, 02:22 PM #7
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
When i comment out, adding the combobox you get a good look of how i want it to be.
Last edited by aborgeld; 03-31-2011 at 02:24 PM.
- 03-31-2011, 04:01 PM #8
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
The X alignment of each components needs to be the same.
See How to Use BoxLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
- 04-01-2011, 10:08 AM #9
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Thanks for the reply, i know the documentation, but the hint helped me a lot.
- 04-01-2011, 07:33 PM #10
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Similar Threads
-
Positioning println codes to corners
By javanewby in forum New To JavaReplies: 2Last Post: 09-28-2010, 01:50 PM -
problem positioning a JPanel in a JScrollPane
By gib65 in forum AWT / SwingReplies: 4Last Post: 08-02-2010, 10:34 AM -
Positioning using setBounds
By thayalan in forum AWT / SwingReplies: 4Last Post: 04-28-2009, 01:59 AM -
I obviously don't understand positioning panels
By javatard in forum New To JavaReplies: 2Last Post: 12-10-2008, 07:48 AM -
panel positioning
By shwein in forum New To JavaReplies: 4Last Post: 09-09-2008, 05:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks