For GridLayout, when i set panel.setPreferredSize(new Dimension(0, 0)),
I found that using it gave me the desired layout that looks like the
following:
+------------------+
|+----------------+|
|| ||
|| ||
|| Panel ||
|| ||
|| ||
|+-----+-----+----+|
|| 1 | 2 | 3 ||
|+-----+-----+----+|
+------------------+
but
panel.setPreferredSize(null) OR not setting panel.setPreferredSize(new
Dimension(0, 0))
messed up the gui such that when the size of a JLabel (inside the panel)
is increased and exceeds the panel's display area, the other controls
are pushed away and no longer visible.
Sean - 22 Aug 2005 08:18 GMT
> For GridLayout, when i set panel.setPreferredSize(new Dimension(0, 0)),
>
[quoted text clipped - 21 lines]
> is increased and exceeds the panel's display area, the other controls
> are pushed away and no longer visible.
Try setting the size so that the JPanel is large enough to hold your
controls.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Dimension.html
Babu Kalakrishnan - 22 Aug 2005 20:32 GMT
>> For GridLayout, when i set panel.setPreferredSize(new Dimension(0, 0)),
>>
[quoted text clipped - 26 lines]
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Dimension.html
I don't really understand either the question or the answer - but :
a) The picture certainly doesn't look like that of a GridLayout. Is it a
GridBagLayout ? In which case they are totally different beasts.
b) Calling setPreferredSize() is evil - don't ever use it if you can.
(See point (c) for the reason).
c) As regards to the answer to the question : The whole point of
LayoutManagers is that a container should be able to figure out how big
it ought to be based on the size of its children (and possibly
grandchildren - and so on) irrespective of the platform, user
preferences of font size etc. When you try setting sizes that you think
will make the children fit, you're defeating the purpose of
LayoutManagers altogether. In which case one could as well have used a
null LayoutManager (God forbid).
BK