如何在Eclipse RCP 3.x中设置向导窗口的标题?

时间:2014-02-12 17:46:35

标签: java eclipse eclipse-plugin eclipse-rcp jface

如何在Eclipse RCP 3.x中设置向导窗口的标题?

此代码

    Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
    WizardDialog dialog = new WizardDialog(shell, new ChatNewWizard());
    dialog.setTitle("New chat");
    dialog.open();

从处理程序执行,没有任何效果。

此代码

getShell().setText("New chat");

和此代码

((WizardDialog)getContainer()).setTitle("New chat");
addPages()执行的

也没有效果。

更新

以下代码

public class RunWizardHandler extends AbstractHandler {

    public static class MyWizardPage extends WizardPage {

        protected MyWizardPage() {
            super("Page Name", "Page Title", null);
            setDescription("Page Description");
        }

        @Override
        public void createControl(Composite parent) {

            Composite composite = new Composite(parent, SWT.NONE);
            composite.setLayout(new FillLayout());

            Label label = new Label(composite, SWT.NONE);
            label.setText("Label Text");

            setControl(composite);
        }

    }

    public static class MyWizard extends Wizard {

        @Override
        public void addPages() {
            addPage(new MyWizardPage());
        }

        @Override
        public boolean performFinish() {
            return false;
        }

    }

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
        WizardDialog dialog = new WizardDialog(shell, new MyWizard());
        dialog.open(); 

        return event;
    }



}

从简单样本中运行,给出以下窗口

enter image description here

即。它将“页面标题”放入位置1,而我想在位置2中设置文字。

2 个答案:

答案 0 :(得分:3)

使用WizardPage(String pageName, String title, ImageDescriptor titleImage)构造函数为每个页面指定标题。或者,只要您想更改标题,请致电WizardPage.setTitle(xxx)

当前向导页面标题会覆盖正常的对话框标题(即使未设置)。

更新: 对于对话框切片栏中的标题,请使用WizardDialog.setWindowTitle调用(通常在构造函数中)。

答案 1 :(得分:0)

我不确定这是否是最好的方法,但至少对我有用:

    WizardDialog dialog = new WizardDialog(shell, wizard) {
        @Override
        public void create() {
            super.create();
            getShell().setText("Some nice window name");
        }
    };