• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Help with GridBagLayout resize behaviour

 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've inserted before creating my JFrame, but it doesn't seem to make any difference.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic