简体   繁体   English

从jface对话框中删除按钮栏

[英]Remove button bar from jface dialog

I would like to create a dialog without the OK/Cancel buttons. 我想创建一个没有“确定/取消”按钮的对话框。 I know that if you override the createButton method, this can be achieved. 我知道,如果您覆盖createButton方法,则可以实现。

What do you think of overriding the createButtonBar method to return null if the button bar is not required at all? 如果根本不需要按钮栏,您如何覆盖createButtonBar方法以返回null? This would save some code. 这样可以节省一些代码。

Overriding createButtonBar is going to produce errors if you return null for the result composite as the Dialog code expects it to not be null. 如果您为结果组合返回null ,则覆盖createButtonBar将产生错误,因为Dialog代码希望它不为null。

You can override createButtonsForButtonBar and not create any buttons. 您可以覆盖createButtonsForButtonBar而不创建任何按钮。 It looks like Dialog always checks that individual buttons exist. 看起来Dialog总是检查单个按钮是否存在。

You can remove the space used by the buttons composite like this: 您可以像这样删除组合按钮所使用的空间:

@Override
protected void createButtonsForButtonBar(final Composite parent)
{ 
  GridLayout layout = (GridLayout)parent.getLayout();
  layout.marginHeight = 0;
}

If you want to have the only one "Close" button on your dialog, you can do it so: 如果要在对话框上只有一个“关闭”按钮,可以这样做:

@Override
public void create() {
    super.create();
    getButton(IDialogConstants.OK_ID).setVisible(false);
    getButton(IDialogConstants.CANCEL_ID).setText("Close");
}

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

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