Who wrote that f*** GridLayout?

I have a JFrame with a BorderLayout and set a JPanel to its center. This panel has a GridLayout with some components.
When I start the frame with a pack()-size, everything is ok. But when the frame’s size gets changed smaller, the whole thing
messes up: all components get disordered. But the best is, after widening the frame, this crap order persists.
I aksed for a solution in another forum, but I only got this (sad, but funny too) adress :
http://madbean.com/anim/totallygridbag

Does anyone know a workaround?

hehe look like your talking about GridBagLayout

gridlayout is so simple you can’t mess anything with it (well I don’t use it as it’s not powerful enough so I might be wrong).

Have a look at FormLayout from jgoodies : it supports better resizing and is quite simple to use.

Lilian

Can you provide a couple of screen shots about what your problem is?

yepp, i know its not the GridBagLayout, but it was said they they have problems in common. furthermore its a funny
clip. i have made some screenshots:

at start, all ok:

http://zeus.fh-brandenburg.de/~huellein/1.jpg

resized (smaller), elements are disordered:

http://zeus.fh-brandenburg.de/~huellein/2.jpg

resized again (larger), still disorder:

http://zeus.fh-brandenburg.de/~huellein/3.jpg

I don’t really see what the problem is. Make the Window smaller vertically, and life will be roses.

Just an FYI, Java layout managers all draw components so that the fill the entire area. In this case your grid cells are large, so GridLayout fills the cells with the components. If you don’t want the components to do this (e.g. you want lots of extra space around them) either find a third party layout manager that does what you need, or write your own. :slight_smile:

P.S. Frame.pack() will auto-fix the window size for you.

You don’t even need to do that. You can just put that panel in the east of another panel. Then put the second panel in the north instead of center.

[quote=“CaptainJester,post:6,topic:26466”]
I’m not following you.

  1. He only has one panel.
  2. That would generate a layout with one panel above the other. Why not just use North and South?

normal ppl use a springlayout

because north and south use up the minimal size while the center one takes up what ever space is left north and center makes sense.

[quote]Version note: Before 1.4, the preferred names for the various areas were different, ranging from points of the compass (for example, BorderLayout.NORTH for the top area) to wordier versions of the constants we use in our examples. The constants our examples use are preferred because they are standard and enable programs to adjust to languages that have different orientations.
[/quote]
oooh poor me use page start and center. 8)

hmm actually looking at it again, the text field at 1,2 suddenly end up at location 2,2 etc.
can you show me the code where you add the components?

You might try TableLayout…it’s what I use and has a lot more capabilities than GridBagLayout and MUCH easier to use.

http://jcommon.dev.java.net

-Matt Hicks

TableLayout… it’s what I used instead of gridbag layout. You have excellent control over sizes and resizing.
https://tablelayout.dev.java.net/ … the tutorial is quite good and not too big.

Kova,

Actually, the TableLayout you refer to is different from the one I referenced. I actually used to use that one but switched to the one in JCommon because it’s much easier to use and much more flexible.

-Matt Hicks

[quote=“jbanes,post:7,topic:26466”]

I mean if he wants to make it so that his widgets don’t change size, he could put a panel within a panel within another panel.

Panel 1 is GridLayout
Panel 2 is BorderLayout and panel 1 is put in the north
Panel 3 is BorderLayout and panel 2 is put in the west.

  • panel 3 is placed in the content pane for the JFrame in the center.

Now you change the size of the frame all you want and the original Panel 1 will not change size.

I am still a little confused, becaus I reall do not understand why the GridLayout behaves like this.

Huh? Perhaps I don’t understand you suggestion. For testing purposes I added one GridLyout-Panel into the Center of an BorderLayout JFrame(). When I use frame.pack()
it works. But as soon as I modify the size (even if i drag it wider!) it gets disordered. Changing the size, vertically, horizontally, smaller, larger whatever does not restore my
order.
So, wheres the logic? Why does not the order gets the main priority? I think, if the screen gets larger, theres no problem, then all components can be widened too.
If it gets smaller you can shrink all components as far as they all can be displayed. Then you have to cut something off.

Other suggestions to LayoutManagers are nice but for some reasons I need to fix the problem with GridLayout.

could you show your code / Isolate it in a separate program?

It is really annoying how layout managers force the components to fill the available space sometimes. The JCommon TableLayout allows you to disable filling on an individual component level or on the entire table. Also, you may end up having to do something like a FlowLayout inside of a GridLayout if you’re sure you want to use GridLayout.

-Matt Hicks

its not about the suspected behavoir its the unexpected behavoir the order changes.