Using the SWT MessageDialog

SWT.OK


SWT.OK | SWT.CANCEL

SWT.ICON_INFORMATION

SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION

SWT.RETRY | SWT.CANCEL | SWT.ICON_ERROR

SWT.RETRY | SWT.ABORT | SWT.IGNORE | SWT.ICON_WARNING

Full working example: Main.java:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
 
public class Main {
   public static void main(String[] args) {
      Display display = new Display();
      Shell shell = new Shell(display);
 
      MessageBox dialog = new MessageBox(shell, SWT.OK);
      dialog.setMessage("The 11th of September has learned us...");
      dialog.setText("Information");
      printResult(dialog.open());
       
      dialog = new MessageBox(shell, SWT.OK | SWT.CANCEL);
      dialog.setMessage("that it's not cool to die from hunger.");
      dialog.setText("Information");
      printResult(dialog.open());
 
      dialog = new MessageBox(shell, SWT.ICON_INFORMATION);
      dialog.setMessage("Click CANCEL");
      dialog.setText("Information");
      printResult(dialog.open());
       
      dialog = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
      dialog.setMessage("Do you really want to format your neighbor's drive?");
      dialog.setText("Question");
      printResult(dialog.open());
 
      dialog = new MessageBox(shell, SWT.RETRY | SWT.CANCEL | SWT.ICON_ERROR);
      dialog.setMessage("You don't have a neighbor.");
      dialog.setText("Error");
      printResult(dialog.open());
       
      dialog = new MessageBox(shell, SWT.RETRY | SWT.ABORT | SWT.IGNORE | SWT.ICON_WARNING);
      dialog.setMessage("Don't you really want to not discontinue the proceeding task?");
      dialog.setText("Warning");
      printResult(dialog.open());
       
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch()) {
            display.sleep();
         }
      }
       
      display.dispose();
   }
    
   public static void printResult(int result) {
      switch (result) {
         case SWT.OK:
            System.out.println("SWT.OK");
            break;
         case SWT.CANCEL:
            System.out.println("SWT.CANCEL");
            break;
         case SWT.YES:
            System.out.println("SWT.YES");
            break;
         case SWT.NO:
            System.out.println("SWT.NO");
            break;
         case SWT.ABORT: 
            System.out.println("SWT.ABORT");
            break;
         case SWT.RETRY:
            System.out.println("SWT.RETRY");
            break;
         case SWT.IGNORE:
            System.out.println("SWT.IGNORE");
            break;
         default:
            System.out.println(result);
            break;     
      } 
   }
}