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