我正在开发 SWT 应用程序。它在 Windows 上运行良好,但当我在 Mac 上运行相同的代码时。 我的外壳右上角有一个全屏按钮。
单击该全屏按钮后,应用程序停止响应并且没有任何反应。我想禁用该全屏按钮的点击。
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/