如何在SWT/Java App的Mac OS中禁用全屏按钮? [英] How to disable fullscreen button in Mac OS in SWT / Java App?

查看:148
本文介绍了如何在SWT/Java App的Mac OS中禁用全屏按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on SWT app. It works fine on windows, but when I run the same code on mac. I get a full screen button on right corner of my shell.

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

On clicking that full screen button the app stop responding and nothing happens. I want to disable the click on that fullscreen button.

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

请帮助.我已经通过一些链接了,但是却不知道如何在Mac中禁用该全屏按钮.

Please help. I have gone through this some link but didn't got how to disable that full screen button in 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);

这对我有用.

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

**** *EDIT* ***************

上面的代码没有在Windows中运行,因为没有公认的"NSWindow"类. 要在Windows和Mac上使用通用代码,请使用以下代码.

The above code is not running in windows, as no recognised "NSWindow" class. For using common code for both window and mac use the below code.

public static boolean isWindows() {

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

     }

///检查OS是否为Window,然后按如下所示更改代码

/// Check if OS is Window, Then change the code as follow

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();            

这篇关于如何在SWT/Java App的Mac OS中禁用全屏按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆