2

I want to create a GUI in Swing which contains two vertical sections:

+-----------------------+
| labels,textfields     |
|   and buttons         |
+-----------------------+
|                       |
| chart display         |
|                       |
|                       |
+-----------------------+

I want the first section to take about 30% of the vertical space and the second about 70%. How can I achieve this with Java Swing?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Moonlit
  • 5,171
  • 14
  • 57
  • 95
  • 1
    This [answer](http://stackoverflow.com/a/11166903/1057230), might can help you in that :-) Just use two `JPanel`s as top and bottom and use `GridBagConstraints` providing `weighty = 0.3 for upper JPanel` and `weighty = 0.7 for the lower JPanel`, `weightx = 1.0 for both the JPanel`, that will do. – nIcE cOw Jan 23 '13 at 12:55
  • Remember to accept the answer that worked for you. – Alfergon Jan 23 '13 at 14:55
  • See VerticalLayout from SwingLabs SwingX library – MadProgrammer Jan 23 '13 at 19:57

3 Answers3

3

I would recomend using GridBagLayout for the cases in which you want to controll the size of the layout's components as it allows to put weights on the components.

How to use GridBagLayout

Alfergon
  • 5,463
  • 6
  • 36
  • 56
3

See also JSplitPane.setDividerLocation(int) & How to Use Split Panes.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
2

Use a layout manager like BorderLayout. The top one would go to BorderLayout.NORTH, the bigger one to BorderLayout.CENTER.

Dan D.
  • 32,246
  • 5
  • 63
  • 79