Sign in to follow this  
Kaze

[java] java swing grid size

Recommended Posts

Right now I have a grid layout that I want to compact to its minimal size but in general all the swing components have a min, max and preferred size. How do I select what one the layout manager obeys.

Share this post


Link to post
Share on other sites
Then back to the first question is their any way to make a grid layout take up the minimum amount of space instead of maximum.

I am having a lot of trouble figuring out how to use layout managers and the massive number of options that do nothing except under very specific circumstances isn't helping.

Share this post


Link to post
Share on other sites
I don't know if this will be any help, and might just serve to fuel your already raging fire, but laying out Java swing GUI components by hand is very challenging.

I do not know how to use the GridLayout, because I gave up trying to do this stuff by hand years ago.

Since no one else has answered you, I'll give you a brief history of my experiences with Java GUIs (I've been messing with them for 10 years now).

I started laying them out by hand, using a combination of BorderLayouts, FlowLayouts, and null layouts.
I switched to JBuilder GUI builder, which worked OK. That IDE is no longer free.
I tried NetBeans, but at that time, it didn't work very well.
Next I started using Eclipse Visual Editor, which worked well for a while, until it stopped being supported.
My last job has half a dozen of my GUIs which can no longer be edited without an old Eclipse 3.2 and VE plugin.

Currently, I use MigLayout, which is kind of like doing it by hand, but a lot easier. If you are not doing this
for school, and it doesn't matter which library or Layout Manager you use, I would give it a try...

[url="http://www.miglayout.com"]MigLayout[/url]

Share this post


Link to post
Share on other sites
If you still want to give GridLayout a try, the trick with it is that all the cells will be the size of the largest component in any one of the cells. So all components will be expanded to fill the same amount of space. One way to shrink the size is if you are using buttons in the grid you can set the insets on the buttons to be smaller than normal. That will reduce the overall size of the button.

I don't have any problems working with layout managers, so if you show some code of what you are trying to do, or show a screenshot and say what is wrong with it, I can probably point out the problem.

Share this post


Link to post
Share on other sites
So far the best solution I have found is to use gridbag and have a dummy cell with the weight set to 9999 to make all the other cells compact, is this as good as it going to get or is their a better way?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this