JFace/SWT:更改 InputDialog 中按钮的标签

发布于 2024-09-14 06:02:17 字数 663 浏览 1 评论 0原文

我想创建一个带有“确定/取消”按钮的自定义标签的输入对话框。我正在使用 org.eclipse.jface.dialogs.InputDialog

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

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

它有效,但按钮没有调整大小(并且自定义文本结果被裁剪)。

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

正确的做法是什么?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小瓶盖 2024-09-21 06:02:17

试试这个

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

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);
 }
拥有 2024-09-21 06:02:17

尝试用这种方式..

@Override
protected void createButtonsForButtonBar(Composite parent) {

    Button button = createButton(parent,9999, "HEllo", true);
    Button button2 = createButton(parent,9999, "HEllo232323sdsdsdsd", false);

}

try in this way..

@Override
protected void createButtonsForButtonBar(Composite parent) {

    Button button = createButton(parent,9999, "HEllo", true);
    Button button2 = createButton(parent,9999, "HEllo232323sdsdsdsd", false);

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文