How to disable fullscreen button in Mac OS in SWT / Java App?

主宰稳场 提交于 2019-12-02 00:55:03
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();            
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!