[java] java swing grid size

Started by
5 comments, last by CaptainJester 12 years, 8 months ago
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.
Advertisement
It is rare for any layout manager to use anything other than preferredLayout.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
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.
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...

MigLayout

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

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.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
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?
You would have to show me what you want to do. If you post a screenshot of what you have now and describe what you want I can help.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement