Java Swing: How can I change the size of one row in a Grid layout and allow it to resize dynamically only horizontally and not vertically?

ksm001 picture ksm001 · Sep 26, 2012 · Viewed 27.1k times · Source

Hi everyone I have a JFrame which has three components inside.

  1. A menu
  2. A tabbed pane
  3. a panel that has some buttons

Initially my goal was to create a design like the following: enter image description here

when the user would resize the application, everything would be resized as well. So I thought maybe if I used a simple grid layout my problem would be solved, so I decided to do the following:

  1. The tabbed pane will have some panels inside and those panels will follow the grid layout.

  2. the Panel at the bottom will follow the grid layout.

  3. the JFrame will follow the grid layout as well.

Results:

enter image description here

As you can see this is not what I wanted, the buttons are too big and although the application resizes very well:

enter image description here

The buttons resize as well but they remain too big. I would like to be able to set a small size for the buttons(more specifically the panel they are contained in) and when the user resizes the application, the buttons would resize only horizontally never vertically which means that ONLY the tabbed pane would grow bigger vertically. Is this achievable? I searched and found out about gridbaglayout, I started playing a little bit, but I didn't achieve anything. All I managed to do is the following:

enter image description here

seems good, but when I resize this is what I get:

enter image description here

thanks in advance.

Answer

splungebob picture splungebob · Sep 26, 2012

I would use BorderLayout for the content pane. Put the tabbed pane in it using BorderLayout.CENTER, and the panel of buttons in it using BorderLayout.SOUTH.