aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help with GridBagLayout resize behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help with GridBagLayout resize behaviour" Watch "Help with GridBagLayout resize behaviour" New topic
Author

Help with GridBagLayout resize behaviour

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441



Here's a panel called panelLower from my GUI. It sits in the the SOUTH BorderLayout position in a JPanel, which is displayed in a frame.
It has a 2x2 GridBagLayout with 2 panels, panelControls and panelPositions, plus a checkbox.
The 2 panels each have GridBagLayouts, of 4x1 and 8x1. panelControls contains 4 panels (Zoom, Move, Detail, Size) which are configured with GroupLayouts or GridBagLayouts.

My problem is this: when I resize the frame, the left-most columns of the GridBagLayouts are squashed. Here's what I mean:

The Zoom panel has shrunk and the first label on panelPositions has disappeared altogether. What I want if for the panels to stay rigid and not shrink at all. Is this possible with the GridBagLayout?

I have set a minimumSize and a preferredSize for each of the panels. Not sure what else I can do.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Try using:



I believe a decorated frame will respect the minimum size of components.

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

I've inserted before creating my JFrame, but it doesn't seem to make any difference.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Works fine for me using the grid bag layout demo code from the Swing tutorial on "How to Use GridbagLayout".
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

If I set the look and feel to the default Metal and include this line, it does respect the minumum sizes. However it makes the frame take the Metal look, as well as the whole GUI, so it's not really a solution. The line doesn't have any effect with Nimbus either either (frame is as per System look and feel).
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Solved it:

I put panelLower in a JScrollPane and turned off both the scrollbars.

Might it be possible to have the same effect using a JViewPort directly, instead of a JScrollPane without scrollbars?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with GridBagLayout resize behaviour