Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout "scrunched" together - messy?" Watch "GridBagLayout "scrunched" together - messy?" New topic
Author

GridBagLayout "scrunched" together - messy?

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi all.
I've an applet which throws a JFrame.
The JFrame constains a relatively complex GridBagLayout.
When the JFrame pops up, and before I maximize it, the components appear "scrunched" up, overlapping one another in a mess, as if swing is trying to fit everything into the minimized JFrame.
However, once I maximize the JFrame, the components are laid out as intended.
Why is this so and how can I prevent the JComponents from being scrunched up before maximizing the JFrame?
TIA :-)


humanum errare est.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
is the initial size of the frame big enough for its content?


SCJP2. Please Indent your code using UBB Code
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
No, when the JFrame pops up, it is in a "minimized" form, rather than taking up all the screen real estate. So no, it's not big enough in that sense. Since I maximize it, there's enough screen real estate to lay out the components.
Is there a way I can work around this?
Perhaps put the whole GridBagLayout in a JScrollPane ?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Yes that idea is working; it also looks better setting the scrollbar policies to NEVER.
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
The idea works well, but the fine-tuning is puzzling.
Following piece of code achieves the desired basic result:

Yet this piece of code, which is nicer but not a show-stopper, throws compile time error:

The compile time error reads:

cannot resolve symbol
symbol : variable ScrollPaneConstants
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535

[ February 04, 2004: Message edited by: Craig Wood ]
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Thanks, Craig, for taking time to look at my issue.
Your approach works for me.
It would be nice though to know why ScrollPaneConstants didn't work...
:-)
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Look in the JScrollPane api at the setVerticalScrollBarPolicy(int policy) method for a listing of the legal values.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout "scrunched" together - messy?