Display an Empty Dialog : Dialog « SWT « Java Tutorial






Display an Empty Dialog
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DialogEmptyDisplay {
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);

    final Shell dialog =new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new RowLayout());

    dialog.pack();
    dialog.open();

    // Move the dialog to the center of the top level shell.
    Rectangle shellBounds = shell.getBounds();
    Point dialogSize = dialog.getSize();

    dialog.setLocation(
      shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
      shellBounds.y + (shellBounds.height - dialogSize.y) / 2);


    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue
        display.sleep();
      }
    }
    display.dispose();
  }

}








17.109.Dialog
17.109.1.Using the Dialogs
17.109.2.Create a dialog shellCreate a dialog shell
17.109.3.Create a dialog shell and position itCreate a dialog shell and position it
17.109.4.Create a dialog shell (prompt for a value)Create a dialog shell (prompt for a value)
17.109.5.Creating Your Own Dialogs
17.109.6.Create your own dialog classes which allows users to input a StringCreate your own dialog classes which allows users to input a String
17.109.7.Prevent escape from closing a dialog
17.109.8.Display an Empty DialogDisplay an Empty Dialog