GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Setting minimum size for a java.awt.Frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting minimum size for a java.awt.Frame" Watch "Setting minimum size for a java.awt.Frame" New topic
Author

Setting minimum size for a java.awt.Frame

Its Just Me
Greenhorn

Joined: Jan 10, 2002
Posts: 21
Hi everyone!
How do I set a minimum size for a java.awt.Frame? I want users to be able to resize my application, but I don't want them to resize it too small. Is this possible with a java.awt.Frame?
[ February 06, 2002: Message edited by: van Hooff ]
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
i dont think u can.
you can either make it non resizable alltogether, or u can override the getminimumSize() method to set the minum size of the frame. BUT if u let the users resize it they can do whatever they want.
one more option i can think of but havent tried is to use the ComponentListener and override the method ComponentResized and then in that fucntion check the size, and if its too small then resize the window again to your minimum size.
Its Just Me
Greenhorn

Joined: Jan 10, 2002
Posts: 21
Thanks,
overriding the componentResized-method of the ComponentAdaptor works. Here's the code I added:
void Frame1_ComponentResized(java.awt.event.ComponentEvent event)
{
Dimension newDim = this.getSize();
if(newDim.height < 600)
{
newDim.height = 600;
}
if(newDim.width < 650)
{
newDim.width = 650;
}
this.setSize(newDim);
}
The Frame is still mini-, maximizable and resizable. If the Frame gets resized too small, it will resize automatically to the specified dimensions.
Thanks for your help.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
great code.
glad to see it worked
 
GeeCON Prague 2014
 
subject: Setting minimum size for a java.awt.Frame