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 thingmesses 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

yepp, i know its not the GridBagLayout, but it was said they they have problems in common.

No they don't. GridBagLayout and GridLayout are entirely different.

Quote

clip. i have made some screenshots:

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.

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.

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.

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.

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.

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.

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?

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 GridLayoutPanel 2 is BorderLayout and panel 1 is put in the northPanel 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.

Quote

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.

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 myorder.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.

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.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org