【问题标题】:How to set the title of wizard window in Eclipse RCP 3.x?如何在 Eclipse RCP 3.x 中设置向导窗口的标题?
【发布时间】:2014-02-12 17:46:34
【问题描述】:

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;
    }



}

从简单示例运行,给出以下窗口

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 我在任何情况下都看不到任何对话框标题。这就是我想要设置的。请查看我的更新。
    • 小修正,现在是WizardDialog.setWindowTitle,改为Wizard.setWindowTitle
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2012-01-04
      相关资源
      最近更新 更多