JFace/SWT: Change the labels for buttons in InputDialog

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

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?

What is the correct way ?

回答1:

try this

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


回答2:

try in this way..

@Override protected void createButtonsForButtonBar(Composite parent) {      Button button = createButton(parent,9999, "HEllo", true);     Button button2 = createButton(parent,9999, "HEllo232323sdsdsdsd", false);  } 


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