简体   繁体   English

如何在JFace向导(Java)中的按钮上设置自定义文本

[英]How to set custom text on buttons in JFace Wizard (Java)

I am using JFace Wizard and I want to set my own text on buttons Next, Back, Finish and Cancel. 我正在使用JFace向导,我想在“下一步”,“上一步”,“完成”和“取消”按钮上设置自己的文本。 I found only very old advices which are completely useless today. 我发现只有很旧的建议,而今天这些建议已经完全没有用了。 I also found some solution with external jar files, but I really don't want to add whole library to project only for setting text on 4 buttons... 我还找到了一些关于外部jar文件的解决方案,但是我真的不想添加整个库来仅用于在4个按钮上设置文本的项目...

Is there any reasonable solution? 有什么合理的解决方案吗?

Thanks in advance 提前致谢

After massive finding and trying, I have to say there is no such way. 经过大量的发现和尝试,我不得不说没有这种方法。 There are some brutal solutions, but compared with them, adding one jar file to project is much easier and nicer. 有一些残酷的解决方案,但是与它们相比,将一个jar文件添加到项目中要容易得多,也更好。

I will cite best working solution for me: 我将为我列举最佳的工作解决方案:

You need to download a language pack from here: 您需要从此处下载语言包:

http://archive.eclipse.org/eclipse/downloads/drops/L-3.2.1_Language_Packs-200609210945/index.php http://archive.eclipse.org/eclipse/downloads/drops/L-3.2.1_Language_Packs-200609210945/index.php

NLpack2-eclipse-SDK-3.2.1-gtk.zip works for me while I'm using Eclipse 3.7.2. 当我使用Eclipse 3.7.2时,NLpack2-eclipse-SDK-3.2.1-gtk.zip对我有用。

Extract org.eclipse.jface.nl2_3.2.1.v200609270227.jar (or other nl for your language) from the archive and add it to your project. 从存档中提取org.eclipse.jface.nl2_3.2.1.v200609270227.jar(或其他使用您语言的nl)并将其添加到项目中。 It will be used automatically. 它将自动使用。

This do not let you to set texts on buttons, but at least gives you texts translated into your language. 这不允许您在按钮上设置文本,但至少可以将文本翻译成您的语言。

Saw this post . 看到这个帖子 Seems to be the answer to your question. 似乎是您问题的答案。 It basically says to create a dialog using WizardDialog class. 它基本上说的是使用WizardDialog类创建对话框。 Create a class that inherits from Wizard with the implementation of your choice then do below: 使用您选择的实现创建一个从Wizard继承的类,然后执行以下操作:

WizardDialog wizardDialog = new CustomWizardDialog(shell, new YourWizard());

and then in your CustomWizardDialog do the following: 然后在您的CustomWizardDialog中执行以下操作:

public class CustomWizardDialog  {
    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        super.createButtonsForButtonBar(parent);

        Button finishButton = getButton(IDialogConstants.FINISH_ID);
        finishButton.setText("FinishButtonText");

        Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
        cancelButton.setText("CancelButtonText");
    }
}

All that is left is to perform wizardDialog.open() to open dialog. 剩下要做的就是执行WizardDialog.open()打开对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM