new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM) (Make shell a dialog) : Shell « org.eclipse.swt.widgets « Java by API






new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM) (Make shell a dialog)

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;


public class MainClass {

  public static void main(String[] a) {
    
    Shell shell = new Shell(new Display());
    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
    dialog.setText("Delete File");
    dialog.setSize(250, 150);

    final Button buttonOK = new Button(dialog, SWT.PUSH);
    buttonOK.setText("OK");
    buttonOK.setBounds(20, 55, 80, 25);

    Button buttonCancel = new Button(dialog, SWT.PUSH);
    buttonCancel.setText("Cancel");
    buttonCancel.setBounds(120, 55, 80, 25);

    final Label label = new Label(dialog, SWT.NONE);
    label.setText("Delete the file?");
    label.setBounds(20, 15, 100, 20);

    Listener listener = new Listener() {
      public void handleEvent(Event event) {
        if (event.widget == buttonOK) {
          System.out.println("OK");
        } else {
          System.out.println("Cancel");
        }
        dialog.close();
      }
    };

    buttonOK.addListener(SWT.Selection, listener);
    buttonCancel.addListener(SWT.Selection, listener);
    
    dialog.open();

  }

}

           
       








Related examples in the same category

1.new Shell(Display arg0)
2.new Shell(Display display, int style)
3.new Shell(Shell parent)
4.Shell: getClientArea()
5.Shell: getDisplay()
6.Shell: open()
7.Shell: setImage(Image img)
8.Shell: setMenuBar(Menu menu)
9.Shell: setRegion(Region reg)
10.Shell: setSize(int width, int height)