user1835297
user1835297

Reputation: 1107

SWT MessageBox close button is disabled

I'm using Java SWT for the application UI. When I use SWT MessageBox in order to ask the user a question, I use:

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. What can I do in order to make it enabled?

Upvotes: 1

Views: 517

Answers (1)

ArcticLord
ArcticLord

Reputation: 4039

I'm sorry for you but this is not possible. From looking into the source code of Java SWT I investigated:
src/org/eclipse/swt/widgets/MessageBox.java Line 206:

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

that runs native C code with JNI: src/os.c Line 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. And there it is not allowed to enable the [X] Button. As your can read here: Enable Close button in Win 32 Message Box
It is only enabled if you add a SWT.CANCEL button, then the [X] acts the same way.

Upvotes: 3

Related Questions