0

I've created a frame and set it extended state to JFrame.MAXIMIZED_BOTH. The window appears maximazed at startup, but after I pressed "Restore" button, it resizes to zero-sized window with only upper part, which contains minimize, maximize and close buttons. After that I can resize window manually, and the content is shown.

I want my window to be maximized at startup, but don't want to lose it after restore button click.

Here is the code:

public class MyFrame extends JFrame { 
      public MyFrame() {
         //...
         setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);        
         setVisible(true);
      }
}

2 Answers 2

2

You should call pack() before setVisible(true) to make sure the preferred size is properly calculated. I think then restore should work properly.

1

Probably you should try this:

public class MyFrame extends JFrame { 
      public MyFrame() {
         //...
         setSize(500,400); // Watever size you want to set.
         setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);        
         setVisible(true);
      }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.