View on GitHub

Eclipse Tutorial

Ecsoya

online tutorialsWIKIoffline tutorialsPPT

JFace Dialogs Tutorial

JFace Dialog和SWT Dialog不同,SWT Dialog主要是一些调用系统已有的对话框,比如颜色,字体等,而JFace Dialog主要是提供了一些便于用户自定义的接口,以便我们实现自己的对话框。

JFace Dialogs

我们常用的JFace Dialog主要有一下一些:

InputDialog

InputDialog inputDialog = new InputDialog(shell, "Input Dialog Tutorial", "Input value", "Hello World", null);
inputDialog.open();

MessageDialog

MessageDialog.openConfirm(shell, "Confirm", "Please confirm");
MessageDialog.openError(shell, "Error", "Error occured");
MessageDialog.openInformation(shell, "Info", "Info for you");
MessageDialog.openQuestion(shell, "Question", "Really, really?");
MessageDialog.openWarning(shell, "Warning", "I am warning you!");

示例:

MessageDialog dialog = new MessageDialog(shell, "My Title", null, "My message", MessageDialog.ERROR, new String[] { "First", "Second", "Third" }, 0);
int result = dialog.open();
System.out.println(result);

如图:

TitleAreaDialog

TitleAreaDialog dialog = new TitleAreaDialog(shell) {
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("TitleAreaDialog Tutorial");
    }
    protected Control createDialogArea(Composite parent) {
        Composite dialogArea = (Composite) super.createDialogArea(parent);
        // add your contents here
        setTitle("Add yout TITLE here");
        setMessage("Add your MESSAGE here");
    return dialogArea;
    }
};
dialog.open();

如图:

WizardDialog

WizardDialog dialog = new WizardDialog(shell, new MyWizard());
dialog.open();

Wizard:

public class MyWizard extends Wizard {
    public MyWizard() {
        setWindowTitle("Wizard Dialog Tutorial");
    }
    public void addPages() {
        addPage(new WizardPage1());
    }
    public boolean performFinish() {
        return false;
    }
}

WizardPage:

public class WizardPage1 extends WizardPage {
    protected WizardPage1() {
        super("WizardPage1");   
    }
    public void createControl(Composite parent) {
        Label control = new Label(parent, SWT.NONE);
        control.setText("Page1");
        setControl(control);
        setTitle("Page1 Title");
        setMessage("Page1 Message");
    }
}

如图:

  1. Wizard是WizardDialog实现的关键,里面可以添加多个WizardPage。
  2. 每个WizardPage必须要实现createControl()方法,并且要调用setControl()方法来设置创建好的控件。

Back to Home 上一篇:TreeViewer Tutorial 下一篇:JFace DataBinding Tutorial