JFace / SWT:更改InputDialog中按钮的标签 [英] JFace/SWT: Change the labels for buttons in InputDialog

查看:164
本文介绍了JFace / SWT:更改InputDialog中按钮的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OK / Cancel按钮的自定义标签创建一个InputDialog。我正在使用 org.eclipse.jface.dialogs.InputDialog

I want to create an InputDialog with custom labels for the OK/Cancel buttons. I'm using org.eclipse.jface.dialogs.InputDialog.

我尝试覆盖按钮创建方法:

I tried to override the button creation method:

   @Override
   protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);
    getButton(IDialogConstants.OK_ID).setText(myOkText);
    getButton(IDialogConstants.CANCEL_ID).setText(myCancelText);
   }

可以,但是按钮的大小没有调整(自定义文本结果

and it works, but the buttons are not resized (and the custom text results cropped).

我想在这里设置文本为时已晚,因为布局管理器已经确定了按钮的大小,并且无法告诉它重新计算...是

I guess it's too late to set the text here, because the layout manager has already decided the button size and one cannot tell it to recompute... Is that so?

正确的方法是什么?

推荐答案

尝试此

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

    Button ok = getButton(IDialogConstants.OK_ID);
    ok.setText(myOkText);
    setButtonLayoutData(ok);

    Button cancel = getButton(IDialogConstants.CANCEL_ID);
    cancel.setText(myCancelText);
    setButtonLayoutData(cancel);
 }

这篇关于JFace / SWT:更改InputDialog中按钮的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆