Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes restrictions on resizing JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "restrictions on resizing JFrame" Watch "restrictions on resizing JFrame" New topic

restrictions on resizing JFrame

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
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

Joined: Jul 26, 2007
Posts: 10815

Try out setPreferredSize()

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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)
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

Joined: Oct 27, 2005
Posts: 20269

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: restrictions on resizing JFrame
It's not a secret anymore!