• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with GridBagLayout resize behaviour

 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using:



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

 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've inserted before creating my JFrame, but it doesn't seem to make any difference.
 
Rob Camick
Ranch Hand
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine for me using the grid bag layout demo code from the Swing tutorial on "How to Use GridbagLayout".
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic