Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How Do You Set the Maximum Size of a JFrame?

843806Nov 14 2007 — edited Nov 14 2007
Can someone show me a quick example? The JFrame can be empty, I just want to know how to set it's maximum size. I tried using setMaximumSize() and it doesn't work for some reason but setMinimumSize() works fine.

I tried it using a BoxLayout and even using null as a layout manager and can't get it to work. I heard that the other layout managers don't allow you to set the maximum size of a JFrame so that is why I tried it with the layouts that I did.

I tried the following code (imported the necessary classes), but it does not work...
public class MyFrame extends JFrame
{
    public MyFrame()
    {
        super("TestFrame");
        setLayout( new BoxLayout(getContentPane(), BoxLayout.X_AXIS)  );        
        setMaximumSize( new Dimension(400,200)); 
        setSize(300,150);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible( true );                 
    }
    
    
}// end class
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 12 2007
Added on Nov 14 2007
13 comments
1,093 views