
Signature
Eric Sosman
esosman@acm-dot-org.invalid
>> them in the BorderLayout.CENTER of a JApplet, however when I try to put
>> them together and use BorderLayout{.EAST, .CENTER, .WEST}, the panel of
>> the left gets squeezed to the point you can not see it.
> Have you tried setting preferred sizes or minimum sizes
>for the JPanels or for their contents? See the JavaDoc for
>the JComponent methods setPreferredSize, et al.
This is likely enough to solve the immediate problem. Minimum and Preferred
sizes are vital to letting your layoutmanager know how you expect to be
displayed.
However, I'll pass along a piece of advice I was given long ago, which I now
ignore often but still has a ton of value:
Use only GridBagLayout.
This is worthwhile for two reasons: First, you will learn more about
AWT/Swing layout from doing a few mildly complex GridBag layouts than you will
from doing dozens of Border/Box/Grid layouts.
Second, you will realize that the spec for a good resizable layout is harder
than you think, and in putting together GridBagConstraints for each component
you will get a much better understanding of how you want your app to work.
It's possible that SpringLayout has replaced GridBagLayout for this level of
generality, and you should learn that instead (or in addition).
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
Babu Kalakrishnan - 19 Sep 2006 21:14 GMT
>>>them in the BorderLayout.CENTER of a JApplet, however when I try to put
>>>them together and use BorderLayout{.EAST, .CENTER, .WEST}, the panel of
[quoted text clipped - 12 lines]
>
> Use only GridBagLayout.
I would disagree with that advice - pretty strongly. There are places
where a GridBagLayout would be the ideal one - but there are tons of
situations where it is very ill-suited to serve the purpose and
misbehaves pretty badly. (For example try putting a JScrollPane inside a
GridBagLayout - you'll find that the layout doesn't behave as one
expects when the container is resized with whatever combinations of
constraints you use - you'd be forced to fiddle with minimum sizes /
preferred sizes to get it to behave in a reasonable manner). Any
component that has a minimum size that is very different from its
preferred size does not play well with a GridBagLayout - (I'm of the
opinion that this is a defect in its implementation - Sun doesn't agree
with it though)
So the best thiong to do is - learn about the strengths and weaknesses
of the different layout managers available, and use the one (or multiple
ones) that most appropriate for the job at hand (And the capability to
make that decision comes only when you know what each layout manager is
capable of doing, and what it cannot do)
BK
Larry Barowski - 20 Sep 2006 14:29 GMT
> ... There are places
> where a GridBagLayout would be the ideal one - but there are tons of
[quoted text clipped - 8 lines]
> opinion that this is a defect in its implementation - Sun doesn't agree
> with it though)
I'd say they do agree, since this problem was fixed twice. Both times
the fix was backed out because it broke existing applications. I'm
not too upset with that because in this case it isn't really a bug, it's
just not-very-useful behavior. In other cases though, they have done
the same for the same reason with things that are bugs.
The version of GBL that distributed extra space so that the fraction
of space difference between minimum and preferred size for each
component was distributed equally when preferred sizes could not
be reached was pretty good. I think that may have been in some of
the 1.5 Betas or early access versions.
Babu Kalakrishnan - 20 Sep 2006 14:46 GMT
>>... There are places
>>where a GridBagLayout would be the ideal one - but there are tons of
[quoted text clipped - 20 lines]
> be reached was pretty good. I think that may have been in some of
> the 1.5 Betas or early access versions.
Possible that my information is somewhat out of date since I haven't
been dabbling much in Swing the past couple of years. The basis of my
statement was some of their own comments in bug reports related to the
issue which went something like - "Not a bug - will not be fixed"
If they did fix the GBL behaviour and it caused backward incompatibility
issues, the least they could have done was to release the fixed version
as say "GridBagLayout2" (After all they do have an interface named
LayoutManager2 - so I think they would be OK with the ugliness of the
class name :-) )
BK
Larry Barowski - 20 Sep 2006 21:45 GMT
> If they did fix the GBL behaviour and it caused backward incompatibility
> issues, the least they could have done was to release the fixed version
> as say "GridBagLayout2" (After all they do have an interface named
> LayoutManager2 - so I think they would be OK with the ugliness of the
> class name :-) )
Agreed. Or they could just add a constructor with a flags
argument to GridBagLayout, so that various aspects of
the layout behavior could be selected.