Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamically changing the size of JDialog  RSS feed

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two Jpanels, but at a time one JPanel will be displayed in the JDialog..
in other words one Jpanel toggles the other panel and vice versa.. (inside JDialog)

Iam facing problem in aligning the contents in the Panel w.r.t JDialog while switching
The problem is One panel has got more componets to display than the other panel..

I have used dialog.setSize(width,height) method to change the size dynamically, but it is not working properly
first time it displayed properly, but upon switching between panels...the dialog border has been cut..i.e. partial dialog was displayed(w.r.t new dimensions)

I need some suggestions in solving this problem.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after adding the panel, try
dialog.pack();
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:after adding the panel, try
dialog.pack();


also, rather than call "setSize(...), call setPreferredSize(new Dimension(...)) on the JDialog or better on the JPanel it holds, and then call pack() as Michael recommends above.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And since Pete somehow didn't, I would suggest you take a look at CardLayout.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!