Open Mac fullscreen out of java application

2019-09-05 23:46发布

my Java application is able to use fullscreen mode with mac thanks to this code:

Class util = Class.forName("com.apple.eawt.FullScreenUtilities");
Class params[] = new Class[]{Window.class, Boolean.TYPE};
Method method = util.getMethod("setWindowCanFullScreen", params);
method.invoke(util, myJFrame, true);

But this only enables fullscreen button at the right upper corner. Is it possible to go to fullscreen mode out of the application, as example by JButton-click?

It's only relevant for Mac OS X.

Thanks!

1条回答
Melony?
2楼-- · 2019-09-06 00:43

If you're using OS X (10.7 and higher), you can use the native fullscreen mode. Use this method to request the window go on full screen mod :

com.apple.eawt.Application.getApplication().requestToggleFullScreen(window);

Where window is your JFrame for example.

EDIT : You can also see the example given by @trashgod in his comment.

Hope this could help.

查看更多
登录 后发表回答