简体   繁体   English

SWT MessageBox关闭按钮被禁用

[英]SWT MessageBox close button is disabled

I'm using Java SWT for the application UI. 我正在使用Java SWT作为应用程序UI。 When I use SWT MessageBox in order to ask the user a question, I use: 当我使用SWT MessageBox向用户询问问题时,我使用:

MessageBox messageBox = new MessageBox(new Shell(Display.getCurrent()), SWT.YES | SWT.NO | SWT.ICON_QUESTION);

But when the dialog is open, the close (red X button) is disabled. 但是当对话框打开时,关闭(红色X按钮)被禁用。 What can I do in order to make it enabled? 我该怎么做才能启用它?

I'm sorry for you but this is not possible. 我很抱歉,但这是不可能的。 From looking into the source code of Java SWT I investigated: 从查看我调查的Java SWT的源代码:
src/org/eclipse/swt/widgets/MessageBox.java Line 206: src / org / eclipse / swt / widgets / MessageBox.java第206行:

OS.MessageBox (hwndOwner, buffer1, buffer2, bits);

that runs native C code with JNI: src/os.c Line 8939: 使用JNI运行本机C代码:src / os.c第8939行:

rc = (jint)MessageBoxA((HWND)arg0, (LPSTR)lparg1, (LPSTR)lparg2, arg3);

So thats the real Win32 API Code for MessageBox that is encapsulated by Java SWT. 这就是由Java SWT封装的MessageBox的真正Win32 API代码。 And there it is not allowed to enable the [X] Button. 并且不允许启用[X]按钮。 As your can read here: Enable Close button in Win 32 Message Box 您可以在此处阅读: 在Win 32消息框中启用“关闭”按钮
It is only enabled if you add a SWT.CANCEL button, then the [X] acts the same way. 它仅在您添加SWT.CANCEL按钮时启用,然后[X]以相同的方式起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM