2

I'm creating a simple Java Swing application. The build set up is a Grid Layout of 3 rows and 1 column. Inside the top row is another Grid Layout that has two columns, and inside each of those columns another Grid Layout splitting it into 2 rows. Same thing goes for the middle row. The bottom row is just a Flow Layout.

enter image description here

Black = 3 Rows, Blue = Splitting rows into 2 columns, Red = Splitting two columns into 2 rows. Here's the actual picture of the output:

enter image description here

JPanel contentPane = new JPanel(new GridLayout(3,1));
JPanel botPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));

My question is, how do I make the bottom row with the button not have the giant gap in it, but end at the bottom of the button?

RipIt
  • 205
  • 1
  • 8

2 Answers2

4

Use BoxLayout, ra‌​ther than GridLayout, for the enclosing panel. Examples may be found here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
4

change contentPane from (3,1) to (2,1)

add contentPane to the frame at BorderLayout.CENTER

add botPane to the frame at BorderLayout.SOUTH

then frame.pack()

Michael Dunn
  • 818
  • 5
  • 3