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

Programmatically resizing a JFrame

500 views
Skip to first unread message

Stuart Hansen

unread,
Feb 11, 2002, 6:37:11 PM2/11/02
to
I want to programmatically change the width of my application's JFrame.
Everything seems to work fine when I do it with the mouse.

I included the following line in my code to change the size.

frame.setSize(frame.getWidth()+DELTA_WIDTH, frame.getHeight());

Indeed, frame does grow by DELTA_WIDTH.
Nothing shows up in the extra area, however.
If I tweak the size a bit with the mouse, it all shows up.

Do I need to send a message to the frame's layout manager?
Do I need to send a message to the frame's contentPane?
Any help is appreciated.

Thanks,
Stu Hansen


Peter

unread,
Feb 11, 2002, 8:18:47 PM2/11/02
to
Stuart Hansen wrote:

I am not a awt/swing expert but it looks like you have to execute a
repaint after the resize. no?
--

Peter
Looking for a JAVA opportunity in Calgary
http://wilboo.dyn.ca/resume.htm


Stuart Hansen

unread,
Feb 11, 2002, 9:05:06 PM2/11/02
to
Peter wrote:

I have tried repaint on the frame and on the contentPane to no avail.
I have also tried paintImmediately on each of the components in the expanded
area.
None of these solve my problem.

Thanks,
Stu

Frank

unread,
Feb 11, 2002, 10:39:33 PM2/11/02
to
After running frame.setSize(...), you'll probably want to follow it up with
frame.doLayout(). This works under AWT, I presume it should work for swing
as well.

Hope this helps!

Frank

"Stuart Hansen" <han...@cs.uwp.edu> wrote in message
news:3C6855A7...@cs.uwp.edu...

Babu Kalakrishnan

unread,
Feb 11, 2002, 11:15:06 PM2/11/02
to
On Mon, 11 Feb 2002 20:05:06 -0600, Stuart Hansen <han...@cs.uwp.edu> wrote:
>Peter wrote:
>> Stuart Hansen wrote:

>> > I want to programmatically change the width of my application's JFrame.
>> > Everything seems to work fine when I do it with the mouse.
>> >
>> > I included the following line in my code to change the size.
>> >
>> > frame.setSize(frame.getWidth()+DELTA_WIDTH, frame.getHeight());
>> >
>> > Indeed, frame does grow by DELTA_WIDTH.
>> > Nothing shows up in the extra area, however.
>> > If I tweak the size a bit with the mouse, it all shows up.

>> I am not a awt/swing expert but it looks like you have to execute a


>> repaint after the resize. no?

>I have tried repaint on the frame and on the contentPane to no avail.


>I have also tried paintImmediately on each of the components in the expanded
>area.
>None of these solve my problem.

frame.getContentPane().revalidate();
frame.getContentPane().repaint();

BK

Stuart Hansen

unread,
Feb 12, 2002, 6:48:01 AM2/12/02
to
Babu Kalakrishnan wrote:

Thanks.

This works after I cast the contentPane to a JComponent. e.g.
((JComponent)frame.getContentPane()).revalidate();

Stu

Peter

unread,
Feb 12, 2002, 9:49:09 AM2/12/02
to
Stuart Hansen wrote:

Strange, I wrote a little 'test' and resize(x,y) worked perfectly.
I know that calling to much repaint() 's can cause troubles to,
because the operating system then skips 'arbitrarely' some calls. (to speed up
things)
As far as I know if you call repaint on the top window, the components inside
will call repaint automatically.
So that should be enough.
If you like you may send me (a part of) the code so I can take a look at it to.

Alex Molochnikov

unread,
Feb 12, 2002, 12:52:32 AM2/12/02
to
Try jFrame.validate().

Alex Molochnikov
Gestalt Corporation

Stuart Hansen

unread,
Feb 12, 2002, 12:42:23 PM2/12/02
to
Alex Molochnikov wrote:

This also does the trick.
Thanks,
Stu

0 new messages