Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2005

Tip: Looking for answers? Try searching our database.

setPreferredSize(new Dimension(0, 0))

Thread view: 
- - 22 Aug 2005 06:41 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.