20

How can I (natively) implement the fullscreen feature of OSX Lion in a Java application?

The current answers given incorporate a good method for achieving a sort-of-fullscreen feature. I've read that Eclipse may be able to use the "native" fullscreen feature of Lion. That's what I'm asking about.

gamma
  • 1,902
  • 1
  • 20
  • 40

6 Answers6

29

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 JFrames...

/**
 * @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);
    }
}
fommil
  • 5,757
  • 8
  • 41
  • 81
Dyorgio
  • 1,114
  • 13
  • 23
  • Is there a way to check if the application is currently in fullscreen mode or not? Otherwise, toggling fullscreen is utterly useless. – mostruash Apr 21 '13 at 08:14
  • 1
    @mostruash: Yes, you can attach a listener to a window to see if it has entered or exited full screen mode. See the [static methods in com.apple.eawt.FullScreenUtilities](http://cr.openjdk.java.net/~michaelm/7113349/jdk8/webrev.2/jdk/src/macosx/classes/com/apple/eawt/FullScreenUtilities.java.html) and the [definition of com.apple.eawt.FullScreenListener](http://cr.openjdk.java.net/~michaelm/7113349/jdk8/webrev.2/jdk/src/macosx/classes/com/apple/eawt/FullScreenListener.java.html). – Arthur Edelstein Jun 30 '13 at 05:43
6

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.

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
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.

Dakshinamurthy Karra
  • 5,353
  • 1
  • 17
  • 28
1

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.

Tiberiu
  • 508
  • 7
  • 17
  • You did see, that the accepted solution is quite old and that is more powerful due to reflections? – gamma Dec 13 '13 at 10:53
  • My answer is a slightly complementary solution for other users like me that did not wanted to bother with reflection. – Tiberiu Dec 16 '13 at 09:23
0

Please file a bug report with Apple. They maintain Java on OS X and it should conform to their published standards.

-2

Java allows you full screen mode, that has nothing to do with Lion. (via chubbard)

If you want to write native Cocoa applications with Java, you need to use JavaBridge. However, JavaBridge is deprecated.

My recommendation is: If you want to write native OSX Cocoa applications, do it in Objective C or Macruby. MacRuby is currently receiving funding from Apple (Sansonetti is a full-time Apple employee) and might just have a future with Cocoa. Java doesn't.

Community
  • 1
  • 1
nes1983
  • 15,209
  • 4
  • 44
  • 64
  • Your link is the same as the one above. Your native-recommendation makes sense, but we already have a full blown and mature Java implementation of the product. Apple usually had special OSX API's for Java - I hoped Oracle had something similar for the Lion version already. – gamma Jul 31 '11 at 09:48
  • I know the link is the same, I'm trying to give a complete answer. I attribute it to chubbard. Apple did provide that, it was called JavaBridge. The link is above. – nes1983 Aug 01 '11 at 19:21
  • I can add multi platform applications like NetBeans. When running on Mac, the menu is integrated to OSX menu (i.e. no "menu bar" inside the window). They have a "fullscreen" feature, but it's not like Lion's FS. I would love to create a patch and submit it to NB team. – Eduardo Costa Nov 27 '11 at 15:50