0

I've having trouble with the java.awt layout.

I've tried every single layout listed here : http://docs.oracle.com/javase/tutorial/uiswing/layout/ But didn't achieve what I wanted.

I've 2 JPanel. One with a fixed size. A second with the variable width. Both are on the same horizontal level and both have the same height.

The first should be stay at the left side of the JFrame, the second expand when width of the frame increases. There also should be a little gap between them, let's say 5px.

How would you do that ?

Thx.

Ps : There's a look a like example. On the left a panel with the 6 buttons stays on the left. On the right the panel example when expanding the whole window.

enter image description here

Community
  • 1
  • 1
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134

2 Answers2

1

I'd suggest a either GroupLayout or a Nested Layout for this layout. The first is a more recent layout that provides horizontal & vertical groups to align components. The 2nd is merely 'putting layouts inside layouts' to achieve different layout strategies for different areas of the UI (example below).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

One option is to use javax.swing.Box, which uses a BoxLayout and provides convenient methods such as:

  • createRigidArea(Dimension d), which creates an area which (container) with a constant size.
  • createHorizontalStrut(int width), which creates a fixed amount of space between components.

See javax.swing.Box for the API.

Torious
  • 3,364
  • 17
  • 24