Question

I am adding a menu item to the menu bar for my Java application (if using OS X) titled Zoom (aka expand, maximize). Upon clicking it, it should trigger the green zoom stoplight button. I figured out how to programmatically enter Full Screen and minimize to the Dock (setState(Frame.ICONIFIED);), but I have not found a way to initiate zoom. Thanks!

screenshot

Était-ce utile?

La solution

Thanks to vandale, here is the answer should anyone else stumble upon this question:

Use setExtendedState(Frame.MAXIMIZED_BOTH);to initiate zoom.

But realize this is not a toggle, so clicking it again doesn't unzoom like other Mac apps. Here is the necessary code to make it a toggle:

if (yourFrame.getExtendedState() != 6)
    setExtendedState(Frame.MAXIMIZED_BOTH);
else
    setExtendedState(Frame.NORMAL);

Zoomed mode is state 6, normal is 0.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top