JDialog (or any window) sizing  
Author Message
Bill Michaelson





PostPosted: 2005-12-22 4:20:00 Top

java-programmer, JDialog (or any window) sizing 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





PostPosted: 2005-12-22 4:23:00 Top

java-programmer >> JDialog (or any window) sizing Bill Michaelson wrote:
> 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





PostPosted: 2005-12-22 4:40:00 Top

java-programmer >> JDialog (or any window) sizing 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?

Vova Reznik wrote:
> Bill Michaelson wrote:
>
>> 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

 
 
Vova Reznik





PostPosted: 2005-12-22 4:48:00 Top

java-programmer >> JDialog (or any window) sizing 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()


Bill Michaelson wrote:
> 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?
>
> Vova Reznik wrote:
>
>> Bill Michaelson wrote:
>>
>>> 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





PostPosted: 2005-12-22 6:48:00 Top

java-programmer >> JDialog (or any window) sizing 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.

Vova Reznik wrote:
> 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()
>
>
> Bill Michaelson wrote:
>
>> 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?
>>
>> Vova Reznik wrote:
>>
>>> Bill Michaelson wrote:
>>>
>>>> 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
>>
>>
>>

 
 
Andrew Thompson





PostPosted: 2005-12-22 9:39:00 Top

java-programmer >> JDialog (or any window) sizing Bill Michaelson wrote:

> 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.

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





PostPosted: 2005-12-22 16:43:00 Top

java-programmer >> JDialog (or any window) sizing On Wed, 21 Dec 2005 17:48:22 -0500, Bill Michaelson <email***@***.com>
wrote, quoted or indirectly quoted someone who said :

>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).
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
 
Bill Michaelson





PostPosted: 2005-12-23 22:47:00 Top

java-programmer >> JDialog (or any window) sizing Roedy Green wrote:
> On Wed, 21 Dec 2005 17:48:22 -0500, Bill Michaelson <email***@***.com>
> wrote, quoted or indirectly quoted someone who said :
>
>
>>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...