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 / December 2005

Tip: Looking for answers? Try searching our database.

JDialog (or any window) sizing

Thread view: 
Bill Michaelson - 21 Dec 2005 20:19 GMT
I would like my JDialog to pop up with a size that is just adequate to
contain what is within, which includes various components and layouts in
the hierarchy.  I'm hoping someone can tell me in a nutshell what
sequence of operations to perform.
Vova Reznik - 21 Dec 2005 20:22 GMT
> I would like my JDialog to pop up with a size that is just adequate to
> contain what is within, which includes various components and layouts in
> the hierarchy.  I'm hoping someone can tell me in a nutshell what
> sequence of operations to perform.

java.awt.Window::pack()
and Window subs
Bill Michaelson - 21 Dec 2005 20:40 GMT
Thank you so much for the instant response.  It works fine for two of
three cases.  The third case still leaves me with a question.  The
containment hierarchy in question has a JTable in a JScrollPane.  I'd
like to set that portion of the composition to a particular size and
allow the containing JDialog and other elements to be sized around it
automatically.  If I simply call pack(), the JTable area is much too large.

Your recommendation, please?

>> I would like my JDialog to pop up with a size that is just adequate to
>> contain what is within, which includes various components and layouts
[quoted text clipped - 3 lines]
> java.awt.Window::pack()
> and Window subs
Vova Reznik - 21 Dec 2005 20:48 GMT
Preferred size of JScrollPane with JTable inside is:

Component c = new JScrollPane(new JTable());       
System.out.println(c.getClass().getName()+ ": " +c.getPreferredSize());
javax.swing.JScrollPane: java.awt.Dimension[width=453,height=403]

You may change JScrollPane preferred size before calling pack()

> Thank you so much for the instant response.  It works fine for two of
> three cases.  The third case still leaves me with a question.  The
[quoted text clipped - 12 lines]
>> java.awt.Window::pack()
>> and Window subs
Bill Michaelson - 21 Dec 2005 22:48 GMT
Much to my embarrassment, I tried setPreferredSize(int,int) on the
JScrollPane and assumed that the method did not exist for the class when
the compile failed.  I didn't think of using a Dimension object until I
read your post.  I have it working reasonably well now.

Thanks again for helping.  I know this is basic stuff, but it gets
pretty frustrating sometimes.

> Preferred size of JScrollPane with JTable inside is:
>
[quoted text clipped - 21 lines]
>>> java.awt.Window::pack()
>>> and Window subs
Andrew Thompson - 22 Dec 2005 01:38 GMT
> Much to my embarrassment, I tried setPreferredSize(int,int) on the
> JScrollPane and assumed that the method did not exist for the class when
> the compile failed.  

The JavaDocs (or an automplete IDE) are much handy here..
<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JScrollPane.html>

Do a search on 'setpref', and click the link.

'Voila' - setPreferredSize inherets from JComponent and
accepts a Dimension.

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Roedy Green - 22 Dec 2005 08:43 GMT
>Much to my embarrassment, I tried setPreferredSize(int,int) on the
>JScrollPane and assumed that the method did not exist for the class when
>the compile failed.
setPreferredSize came in with JDK 1.5.  Prior to that you must
override getPreferredSize (and brothers).
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Bill Michaelson - 23 Dec 2005 14:47 GMT
>>Much to my embarrassment, I tried setPreferredSize(int,int) on the
>>JScrollPane and assumed that the method did not exist for the class when
>>the compile failed.
>
>  setPreferredSize came in with JDK 1.5.  Prior to that you must
> override getPreferredSize (and brothers).

I haven't been thinking in those terms, but I'm catching on as I scrape
the rust off my Java lobe.  Thanks for the clue...


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.