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

▼魔方 西西 提交于 2019-12-12 10:22:53

问题


I am using JFace Wizard and I want to set my own text on buttons Next, Back, Finish and Cancel. 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...

Is there any reasonable solution?

Thanks in advance


回答1:


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.

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

NLpack2-eclipse-SDK-3.2.1-gtk.zip works for me while I'm using Eclipse 3.7.2.

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. 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.




回答2:


Saw this post. Seems to be the answer to your question. It basically says to create a dialog using WizardDialog class. Create a class that inherits from Wizard with the implementation of your choice then do below:

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

and then in your CustomWizardDialog do the following:

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.



来源:https://stackoverflow.com/questions/18289553/how-to-set-custom-text-on-buttons-in-jface-wizard-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!