• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

restrictions on resizing JFrame

 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there.

i just want to ask,

well, i have here a JFrame size set as 1024 x 768.
it is resizable.

what i want to know is, how can i restrict the frame from resizing when it reaches 800 x 600?

i mean, when resized, the smallest possible size of the frame must be 800 x 600 and will not go smaller than that.

any suggestions are very much appreciated. thank you.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try out setPreferredSize()
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> what i want to know is, how can i restrict the frame from resizing when it reaches 800 x 600?

presume you mean resize smaller

the only way I've seen possible do do what you want is to add this line
(prior to creating the frame)
JFrame.setDefaultLookAndFeelDecorated(true);
then
frame.setMinimumSize(new Dimension(800,600));

problem is java's default L&F is not the best looking.

a hack is to add a windowListener which snaps it back to 800,600 if smaller,
then, when snapped-back, you could add code to make it not resizable
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, since Java 5.0 the call to JFrame.setDefaultLookAndFeelDecorated(true); is no longer needed. The minimum size is now adhered to with at least the default look&feel (Metal), the Motif look and feel and the Windows look and feel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic