Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to resize JFrame programmatically?

 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried pack(), validate(), invalidate() but it didn't help.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works OK, doing it this way

 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic