TASK:
I would like to have the frame visible in the Frame.MAXIMIZED_BOTH state, but I also want it to have a predefined normal size, so when the user does not maximize it, the size of the frame will resize to the size I want it to be, AND I want the frame to be maximally displayed first, without visually resizing . And I want the frame to remain maximized until the user maximizes it.
Things I've tried so far:
one)
frame.setExtendedState( Frame.MAXIMIZED_BOTH ); frame.setVisible( true ); frame.setSize( 500, 500 );
Evaluation: the frame will switch to normal (will not remain maximized) => not good.
2)
frame.setSize( 500, 500 ); frame.setExtendedState( Frame.MAXIMIZED_BOTH ); frame.setVisible( true );
Rating. A window (or just its frame) will appear with a size of 500x500, after which the visual size (to the maximum) will be visible => not good. The reason for this is that if the frame is not displayed, the call to setExtendedState() will be deferred until the frame is visible.
3)
frame.setSize( 500, 500 ); frame.setVisible( true ); frame.setExtendedState( Frame.MAXIMIZED_BOTH );
Rating: just like in attempt No. 2, the frame will have a visual resizing => not good.
4) I tried to add a listener component to a frame overriding componentResize() and changing its state. I also tried adding a window state listener overriding windowStateChange() . I also tried adding a window listener overriding windowOpened() .
Rating: all this led to a visual resizing, as in the attempt # 2 => not good.
So what can I do if I want my frame to have a predefined normal size, but I want it to display as much as possible?
EDIT: The whole question has been edited to be more clear, and added code examples (SSCCE).