Fullscreen feature for Java Apps on OSX Lion
Solution 1:
I found this on Apple's Java release notes:
Mac OS X 10.7 Lion Fullscreen Support
Java applications on Lion can now opt into the Fullscreen window feature per-window. Developers can use the com.apple.eawt.FullScreenUtilities class to mark windows as able to be full screened, and the com.apple.eawt.Application.requestToggleFullScreen(Window) method to programmatically request the window enter and exit full screen mode. This API does nothing on Mac OS X 10.6 Snow Leopard.
More explicitly, try calling this early on from the constructor of your JFrame
s...
/**
* @param window
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static void enableOSXFullscreen(Window window) {
Preconditions.checkNotNull(window);
try {
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, window, true);
} catch (ClassNotFoundException e1) {
} catch (Exception e) {
log.log(Level.WARNING, "OS X Fullscreen FAIL", e);
}
}
Solution 2:
I don't know about natively, but Java does support fullscreen applications without needing native code:
http://saipullabhotla.blogspot.com/2012/05/enabling-full-screen-mode-for-java.html
The question is has Apple implemented that with Lion in their JDK.
Solution 3:
For those of you who do not mind a quick and dirty solution:
Call getRootPane().putClientProperty("apple.awt.fullscreenable", Boolean.valueOf(true))
from the Frame constructor. This is what setWindocCanFullScreen
does.
Solution 4:
What you are trying to do can be done through the com.apple.eawt library. Additionally in order to avoid writing code through reflection if you also deploy your application on other OSes like Windows, Linux etc. you should use and distribute embeded within your application the AppleJavaExtensions.jar from Apple.
This is the method to make a frame expandable in full screen:
FullScreenUtilities.setWindowCanFullScreen(window,true);
And this is the method to toggle full screen:
Application.getApplication().requestToggleFullScreen(window);
where the parameter window is the JFrame of your application that you are trying to make full screen capable.
To see an example application have a look at RationalPlan Project.