【问题标题】:Is it possible to change Finish button text to Done in Wizard?是否可以在向导中将完成按钮文本更改为完成?
【发布时间】:2014-05-06 10:50:46
【问题描述】:

我在 Eclipse 插件中创建了一个带有一些页面的自定义向导。这些页面是通过扩展 WizardPage 创建的。向导有 Next back Finish 和 cancel 按钮,一切正常。
现在,我想将完成按钮的名称/文本更改为完成。是否有可能在eclipse中做到这一点?还是我需要自己提供所有按钮,即使这样也可以。

【问题讨论】:

    标签: java eclipse eclipse-plugin swt


    【解决方案1】:

    应该这样做:

    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        super.createButtonsForButtonBar(parent);
    
        Button finish = getButton(IDialogConstants.FINISH_ID)
        finish.setText("Done");
        setButtonLayoutData(finish);
    }
    

    Here 是一个相关问题。

    【讨论】:

    • 在 org.eclipse.jface.wizard.Wizard 类中,我无法覆盖该方法!这适用于对话框而不是向导!我到底应该在哪里使用它?
    • 这是WizardDialog。根据您使用的向导类型,这可能无法直接使用。
    • @Destructor 啊,我的错。您能否发布一些代码,以便我们查看您实际在做什么/使用什么?
    • 用同样的方法搞定了!我将在下面发布答案。 @greg-449:谢谢!
    【解决方案2】:

    这就是我使用向导的方式:

    MyCustomWizard wizard = new MyCustomWizard ("title");
    WizardDialog wizardDialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
    wizardDialog.open();
    

    现在我创建了一个新类,MyCustomDialog 扩展了 WizardDialog:

    public class MyCustomDialog extends WizardDialog {
    
    public MyCustomDialog(Shell parentShell, IWizard newWizard) {
        super(parentShell, newWizard);
    }
    
    @Override
    public void createButtonsForButtonBar(Composite parent){
        super.createButtonsForButtonBar(parent);
        Button finishButton = getButton(IDialogConstants.FINISH_ID);
        finishButton.setText(windowTitle);
    }
    }
    

    现在我将创建向导和向导对话框的代码更改为:

    MyCustomWizard wizard = new MyCustomWizard ("title");
    MyCustomDialog wizardDialog = new MyCustomDialog(Display.getDefault().getActiveShell(), wizard);
    wizardDialog.open();
    

    希望它对某人有用! :) 感谢@greg-449 和@Baz 的帮助

    【讨论】:

      【解决方案3】:

      还有另一种方法可以更改任何按钮的标签。您可以将 WizardDialog 类的 createButton 覆盖为:

      @Override
      protected Button createButton(Composite parent, int id, String label,
                  boolean defaultButton) {
              if (id == IDialogConstants.FINISH_ID) {
                  return super.createButton(parent, id,
                          "Done", defaultButton);
              }
              return super.createButton(parent, id, label, defaultButton);
      } 
      

      【讨论】:

        猜你喜欢
        • 2023-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-05
        相关资源
        最近更新 更多