How to disable fullscreen button in Mac OS in SWT

2019-02-26 19:58发布

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.

enter image description here

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

Please help. I have gone through this some link but didn't got how to disable that full screen button in mac.

1条回答
欢心
2楼-- · 2019-02-26 20:31
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);

This worked for me..

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

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

     }

/// 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();            
查看更多
登录 后发表回答