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

后端 未结 1 1015
别那么骄傲
别那么骄傲 2021-01-22 00:28

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.

相关标签:
1条回答
  • 2021-01-22 01:02
    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();            
    
    0 讨论(0)
提交回复
热议问题