Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

setPreferredSize(new Dimension(0, 0))

16 views
Skip to first unread message

-

unread,
Aug 22, 2005, 1:41:50 AM8/22/05
to
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

unread,
Aug 22, 2005, 3:18:48 AM8/22/05
to
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

unread,
Aug 22, 2005, 3:32:21 PM8/22/05
to

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

0 new messages