java - 如何在 SWT/Java 应用程序中禁用 Mac 操作系统中的全屏按钮?

标签 java macos swt fullscreen

我正在开发 SWT 应用程序。它在 Windows 上运行良好,但当我在 Mac 上运行相同的代码时。 我的外壳右上角有一个全屏按钮。

enter image description here

单击该全屏按钮后,应用程序停止响应并且没有任何反应。我想禁用该全屏按钮的点击。

display = Display.getDefault();
shell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);        
setDialogShell(shell);
getDialogShell().setLayout( new FormLayout());
getDialogShell().setFullScreen(false);

请帮忙。我已经经历过一些link但不知道如何禁用 mac 中的全屏按钮。

最佳答案

display = Display.getDefault();
shell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
//Shell shell = window.getShell();
NSWindow nswindow = shell.view.window();
nswindow.setCollectionBehavior(0);  
nswindow.setShowsResizeIndicator(false);
setDialogShell(shell);
getDialogShell().setLayout( new FormLayout());
getDialogShell().setFullScreen(false);

这对我有用..

**** *编辑* ** *************

上面的代码没有在 Windows 中运行,因为没有可识别的“NSWindow”类。 要在 Windows 和 Mac 上使用通用代码,请使用以下代码。

public static boolean isWindows() {

      return (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0);

     }

///检查操作系统是否为Window,然后更改代码如下

display = Display.getDefault();
        shell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
         //Shell shell = window.getShell();


        if(!isWindows()){
            Field field = Control.class.getDeclaredField("view");
            Object /*NSView*/ view = field.get(shell);
            if (view != null)
            {
                Class<?> c = Class.forName("org.eclipse.swt.internal.cocoa.NSView");
                Object /*NSWindow*/ window = c.getDeclaredMethod("window").invoke(view);

                c = Class.forName("org.eclipse.swt.internal.cocoa.NSWindow");
                Method setCollectionBehavior = c.getDeclaredMethod(
                        "setCollectionBehavior", /*JVM.is64bit() ?*/ long.class /*: int.class*/);
                setCollectionBehavior.invoke(window,0);
            }
            //          NSWindow nswindow = shell.view.window();
            //          nswindow.setCollectionBehavior(0) ; 
            //          nswindow.setShowsResizeIndicator(false);
        }
        setDialogShell(shell);
        getDialogShell().setLayout( new FormLayout());
        getDialogShell().setFullScreen(false);

        getDialogShell().layout();
        getDialogShell().pack();            

关于java - 如何在 SWT/Java 应用程序中禁用 Mac 操作系统中的全屏按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14834207/

相关文章:

macos - 带旋转的图层支持 View 上的核心动画

java - JFace 给 SWT 添加了什么?

java - 如何在不使用序列化的情况下制作 java 对象的深拷贝?

java - Python @property 在处理类声明中的等效项?

java - Java 版本 : Java 6 (in Terminal, Eclipse)和 Java 7(在 Java 控制面板中)的差异来源是什么?

Cocoa - 强制退出所有其他应用程序

java - java 中的 swt 中未打开且菜单未显示

java - SWT中树查看器添加双击展开

java - 如何在对模型使用自动绑定(bind)的 JTable 中显示标题行

java - Spring Boot 分段上传获取空文件对象