Skip to content

Org.eclipse.swt.widgets.Dialog

Simple custom dialog

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * About dialog class.
 */
public class AboutDialog extends Dialog {

    /** Open Modal Dialog. */
    public static final Object openModal(Shell parent) {
        try {
            final int kDefaultStyle = SWT.APPLICATION_MODAL | SWT.CLOSE;
            AboutDialog dialog = new AboutDialog(parent, kDefaultStyle);
            return dialog.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private Object _result;
    private Shell _shell;

    /** Create the dialog. */
    public AboutDialog(Shell parent, int style) {
        super(parent, style);
        setText("SWT Dialog");
    }

    /** Open the dialog. */
    public Object open() {
        createContents();

        _shell.open();
        _shell.layout();

        Display display = getParent().getDisplay();
        while (!_shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }

        disposeContents();
        return _result;
    }

    /** Create contents of the dialog. */
    private void createContents() {
        final int kWindowWidth = 450;
        final int kWindowHeight = 300;
        _shell = new Shell(getParent(), getStyle());
        _shell.setSize(kWindowWidth, kWindowHeight);
        _shell.setText(getText());
    }

    /** Dispose contents of the dialog. */
    private void disposeContents() {
        _shell.dispose();
    }
}

Message Box

MessageBox dialog = new MessageBox(shell, SWT.OK|SWT.CANCEL);
dialog.setMessage("계속 하실래예?");
int returnVal = dialog.open();

Favorite site

References


  1. Wiklipse_-SWT_Dialog.pdf (기존 깨진 파일 이름: SWT_Dialog-_위클립스.pdf)