Remove button bar from jface dialog

2.4k Views Asked by At

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.

What do you think of overriding the createButtonBar method to return null if the button bar is not required at all? This would save some code.

2

There are 2 best solutions below

6
greg-449 On BEST ANSWER

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.

You can override createButtonsForButtonBar and not create any buttons. It looks like Dialog always checks that individual buttons exist.

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;
}
0
Viktor Sirotin On

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