Yass
Yass

Reputation: 63

How to set default answer button in java MessageDialog.openQuestion?

I am writing an eclipse plugin and I am using MessageDialog.openQuestion to pop up a question. The default answer is "Yes" but I want it to be "no". how do I do that?

Example

Upvotes: 3

Views: 209

Answers (2)

Sterconium
Sterconium

Reputation: 579

Try to change the defaultIndex attribute of the MessageDialog constructor.

(Give a look at the docs)

Upvotes: 0

greg-449
greg-449

Reputation: 111142

You can't do that using the openQuestion method. Instead you will have to construct the MessageDialog using one of the constructors:

MessageDialog dialog = new MessageDialog(shell, "title", null, "message",           
    MessageDialog.QUESTION, 1, IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL);

int buttonPressed = dialog.open();

The 1 is the index of the default button.

Upvotes: 2

Related Questions