Skip to main content

Starting a Desktop App Maximized

1 reply [Last post]
generessler
Offline
Joined: 2010-02-02
Points: 0

I have a cross-platform SingleFrameApplication for Mac, Windows, and Linux.
It needs to start Maximized but when Normalized, revert to the last-saved session size. In startup I'm using the code:
show(view);
// Resize application to full screen. Can't find a way to do this in advance.
getMainFrame().setExtendedState(getMainFrame().getExtendedState() | Frame.MAXIMIZED_BOTH);

In the willExit handler I use the complementary code:
getMainFrame().setExtendedState(getMainFrame().getExtendedState() & ~Frame.MAXIMIZED_BOTH);
This allows the normal size to be saved in the session.
This works, but the start in normal size is visible. The frame then maximizes. With most video drivers the difference between the normal size and maximized size is black while the rest of the window is white for a fraction of a second while the window redraws. When shutting down, you can also see the window shrink before it disappears.
This is all very distracting.
If I put the MAXIMIZE code _before_ show, it doesn't work. THe implementation makes it obvious why.
Is there a way to get the functionality I've described without all the artifacts?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
generessler
Offline
Joined: 2010-02-02
Points: 0

Okay ... solved it myself. Had to locate the (frozen) JDesktop code, make a copy of SingleFrameApplication.java, and hack this. There were two small changes. First, set the extended window state just before setVisible in the show() method. A the same point, capture the normal size of the window and save it to client properties as already done when a window is manually maximized. Altogether only 10 lines. You can't do this easily by inheriting from the jdesktop code because a key method is private rather than protected. If anyone is interested in the code, send me a note at gene.ressler@gmail.com.