I am trying to display a message dialog using the below code :
MessageDialog dialog = new MessageDialog(shell, "My Title", null,
"Are you Sure?", MessageDialog.CONFIRM,
new String[] { "Yes","No" }, 0);
The only problem is when the message dialog get displayed it shows the focus on the "Yes" button so if the user hits enter by default "Yes" gets pressed.
How can i put focus on the “No” button so that when ever user hits enter “No” gets pressed.
Please Note that I don’t want to change the order of Buttons. it should be first Yes and Than No.
Just set the last constructor argument to the index of the button you wish to be the default.
According to the Javadoc:
defaultIndex – the index in the button label array of the default button