wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to resize JFrame programmatically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to resize JFrame programmatically?" Watch "How to resize JFrame programmatically?" New topic
Author

How to resize JFrame programmatically?

Ahmet Aksoy
Ranch Hand

Joined: Apr 04, 2005
Posts: 30
I have a JFrame which contains a JSplitPane.
In the JSplitPane, there are 2 JPanels.
Normally second JPanel is invisible, but when the
user presses a button it will become visible.
I want the JFrame to be resized automatically.
When it shows a single panel, its size will shrink;
and when it shows both panels it will become larger.
How can I do that?
Thanks.
Ahmet Aksoy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
depending entirely on how you have your code structured,
possibly all you need to do is include
pack();
in the button code that makes it visible.
Ahmet Aksoy
Ranch Hand

Joined: Apr 04, 2005
Posts: 30
I tried pack(), validate(), invalidate() but it didn't help.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
works OK, doing it this way

Ahmet Aksoy
Ranch Hand

Joined: Apr 04, 2005
Posts: 30
Michael,
Thank you very much for the sample code.
I think the trick is setting "null".
I will try to implement it in my project.
Best regards.
Ahmet Aksoy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to resize JFrame programmatically?
 
Similar Threads
How to prevent continuous repaint when resizing a frame?
JSplitPanes not resizing when JFrame maximized
JSplitPane (expandable closed)
JSplitPane problem
How to size jsplitpane?