Java Layout: GridLayout/GridBag
Hello,
I use IDEA now for the first day and I have some trouble with the options for the layout manager. Normally it is possible to customize your layout by hand. But here the source code is generated automatically, without the option to "correct" things.
For example, I want to create a GridBag layout with two panels. One on top and one on the bottom. I add a pane in the top pane and inside of this pane, I add two buttons. The vertical-align I set to Top. In the bottom pane, I add some more other content. The layout of my main pane is set to GridLayoutManager. What happens is, that both of the panes have the same space, as long as the content is equal. Like shown here:

The problem here is, that the top pane has some space left beneath the two buttons. I'm not able to "give" this space to my bottom pane, which really needs the space, because it is very the whole work is going on.
Changing the mane panes layout to GridBag won't change a thing, because I can't really specify, that the top space should acquire all the space it wants, but not more it needs. This is how it should look like:

So my questions are as follows:
Is there a possibility to edit the GridLayouts in some way?
Is there a way to give the space to pane for the space it needs, without setting the maximum/minimum height? Just like the "auto" function in C# grid layout?
Also in C#, it is possible to give weight to the flexible layout. I can give a column/row the "*" as a weight or height attribute. What happens it takes the rest of the available space. If I use a "2*" in one component and a "*" for another component in the same pane, then the first component gets 2/3 of the available space, while the other component gets 1/3. Is this here possible too?
The designer in IDEA is pretty good, but these layout problems drive me insane.
Please sign in to leave a comment.
It looks like you have some constraints in effect. If you could share a sample project with the form, we'll be able to help you.
Hey Serge,
I have to say, that my understanding of the GridBagLayout combined with my current Layout, which is the GridLayout, was leading me to a false result. I had to overthink the idea and the layout concept itself and after I had it done, I found the correct solution!
For all which are seeking for the same solution, here the result:
First I set the main JPanel to the GridBagLayout. Inside I add one tabbed/pane (for the top), on JPanel for the middle and one JPanel for the bottom. The attribute weight x of the top tabbed-pane I set to 1.0. For the middle layout, I add a processing button right in the middle, which fills the whole pane. The bottom pane (there where the magic will go one) I set to the GridBagLayout as well, together with the attribute weight y to 1.0 for filling the rest of the available height. There I add some other components as I like. And tada! it works! Here the result with the component tree:
The problem with the C# auto scale (using as much as you want, but as less, as you need) is also solved by using the weight x and weight y.
So that's the solution for my questions and problems mentioned above.
Best regards,
JiBREEL.