wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout in panels - resize causes bunching up.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout in panels - resize causes bunching up.." Watch "GridBagLayout in panels - resize causes bunching up.." New topic
Author

GridBagLayout in panels - resize causes bunching up..

Alan Mc Kernan
Ranch Hand

Joined: Oct 13, 2005
Posts: 59
Hey guys,

Relatively new to Swing coding. I have an applicaiton with many panels, all using grid bags.. (I found it the easiest one to get things into the places i want them to be in). Everything looks nice when there is enough space, but when i crop the window to some very small size, instead of just not being able to see most of the panels, they seem to be attempting to dynamically resize to fit the window, and its all getting bunched up and overlapping jlabels etc, how do I stop this ?

Cheers
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Hello.
You aren't very specific about what your GUI looks like, but remember that GridBag is designed for resizing all the components of the display whenever you alter the size of the display.

Some people use a home-made GridBagConstraints class, which makes it much quicker to set up weights, etc. There is one on Cai Horstmann's website, where you add a component like this:


Now, you have to set the constraints properly; that is the hard part of using GridBad.
Remember that the gridX means the column number, and gridY means row number; I got those two the wrong way round at first and got no end of confusion.

The weight means how much you allow the size of each component to change as you alter the size of the whole display; the greater the weight, the more it changes. Since weight is demoninated in doubles rather than int, you can have a lot of variation in change.

The fill determines whether or not each component fills up its allotted space; you can get components far to small because you haven't given them a fill value.

The anchor determines which side or corner of the allotted space your component hangs onto; in my example it says NORTH, so the button will hang onto the top of its space.

The Insets determines how much empty space there is; in this case 5 px at left and right, and 10 at top and bottom, between the component and its allocation.

There is also internal padding, which I have never actually used myself, and gridwidth and gridheight which mean how many rows or columns you use for a particular component.

You will probably have to use fill and weight to get your display to behave itself.

Any use to you???
CR
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Did you get it to work?

Looking back at my post yesterday, I see it is full of spelling mistakes, and I have typed , instead of . Sorry.

CR
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout in panels - resize causes bunching up..
 
Similar Threads
Creating a login screen
repaint frame
Round up game
Problems adding two panels
resizing problem in Frame