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

Setting minimum size for a java.awt.Frame

 
Its Just Me
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great code.
glad to see it worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic