Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full Screen Mode for Mac OS X #12

Open
tofi86 opened this issue Aug 26, 2014 · 0 comments
Open

Full Screen Mode for Mac OS X #12

tofi86 opened this issue Aug 26, 2014 · 0 comments

Comments

@tofi86
Copy link
Collaborator

tofi86 commented Aug 26, 2014

seems to be provided with the Apple Java Extension Library.

See http://saipullabhotla.blogspot.de/2012/05/enabling-full-screen-mode-for-java.html for more details.

package com.myjavaworld.fullscreendemo;

import java.awt.Window;
import java.lang.reflect.Method;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class FullScreenDemo {
    public static void main(String[] args) {
        if (isMacOSX()) {
            System.setProperty(
                    "com.apple.mrj.application.apple.menu.about.name",
                    "Full Screen Demo");
        }
        JFrame frame = new JFrame("Full Screen Demo");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(600, 400);
        if (isMacOSX()) {
            enableFullScreenMode(frame);
        }
        frame.setVisible(true);
    }

    public static void enableFullScreenMode(Window window) {
        String className = "com.apple.eawt.FullScreenUtilities";
        String methodName = "setWindowCanFullScreen";

        try {
            Class<?> clazz = Class.forName(className);
            Method method = clazz.getMethod(methodName, new Class<?>[] {
                    Window.class, boolean.class });
            method.invoke(null, window, true);
        } catch (Throwable t) {
            System.err.println("Full screen mode is not supported");
            t.printStackTrace();
        }
    }

    private static boolean isMacOSX() {
        return System.getProperty("os.name").indexOf("Mac OS X") >= 0;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant