macos OSX Lion 上 Java 应用程序的全屏功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6873568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:15:31  来源:igfitidea点击:

Fullscreen feature for Java Apps on OSX Lion

javamacosfullscreenosx-lion

提问by gamma

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

我如何(本机)在 Java 应用程序中实现 OSX Lion 的全屏功能?

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.

给出的当前答案包含实现某种全屏功能的好方法。我读过 Eclipse 可能能够使用 Lion 的“本机”全屏功能。这就是我要问的。

回答by Dyorgio

I found this on Apple's Java release notes:

我在 Apple 的 Java 发行说明中找到了这个:

Mac OS X 10.7 Lion Fullscreen Support

Mac OS X 10.7 Lion 全屏支持

Java applications on Lion can now opt into the Fullscreen window feature per-window. Developers can use the com.apple.eawt.FullScreenUtilitiesclass 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.

Lion 上的 Java 应用程序现在可以选择每个窗口的全屏窗口功能。开发人员可以使用com.apple.eawt.FullScreenUtilities类将窗口标记为可以全屏显示,并使用com.apple.eawt.Application.requestToggleFullScreen(Window)方法以编程方式请求窗口进入和退出全屏模式。此 API 在 Mac OS X 10.6 Snow Leopard 上不执行任何操作。

More explicitly, try calling this early on from the constructor of your JFrames...

更明确地说,尝试从您的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);
    }
}

回答by chubbsondubs

I don't know about natively, but Java does support fullscreen applications without needing native code:

我不知道本机,但 Java 确实支持全屏应用程序而无需本机代码:

http://saipullabhotla.blogspot.com/2012/05/enabling-full-screen-mode-for-java.html

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.

问题是苹果是否在他们的 JDK 中使用 Lion 实现了这一点。

回答by Dakshinamurthy Karra

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

getRootPane().putClientProperty("apple.awt.fullscreenable", Boolean.valueOf(true))从 Frame 构造函数调用。这就是setWindocCanFullScreen它的作用。

回答by Tiberiu

What you are trying to do can be done through the com.apple.eawtlibrary. 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.jarfrom Apple.

您可以通过com.apple.eawt库完成您想要做的事情。此外,如果您还在其他操作系统(如 Windows、Linux 等)上部署应用程序,为了避免通过反射编写代码,您应该使用和分发嵌入在您的应用程序中的Apple的AppleJavaExtensions.jar

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 windowis the JFrame of your application that you are trying to make full screen capable.

其中参数window是您尝试使其具有全屏功能的应用程序的 JFrame。

To see an example application have a look at RationalPlan Project.

要查看示例应用程序,请查看RationalPlan 项目

回答by Tiberiu

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

请向 Apple 提交错误报告。他们在 OS X 上维护 Java,它应该符合他们发布的标准。

回答by nes1983

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

Java 允许您全屏模式,这与 Lion 无关。(通过chubbard

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

如果要使用 Java 编写本地 Cocoa 应用程序,则需要使用JavaBridge。但是,不推荐使用 JavaBridge。

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.

我的建议是:如果您想编写原生 OSX Cocoa 应用程序,请使用 Objective C 或Macruby。MacRuby 目前正在接受 Apple 的资助(Sansonetti 是 Apple 的全职员工),并且可能与 Cocoa 有未来。Java 没有。