1
votes

So every single time you make a Dialog, there is a createButtonsForButtonBar that you, or WindowMaker will override.

By default, this gives you an OK and Cancel buttons.

The problem:
It would be fine if I could just add custom action to these buttons, but so far I only found limited ways to do this. For example if I add any call to the OK button, it will throw me an exception, that the widget is disposed.

Workaround I used:
So far I managed to just shrink my dialogs, and kept the Override part empty.
This left the bottom part with some empty space, but nothing annoying.
But this is just an ugly workaround and I have to start making smaller dialogs where this is not an option.

What I tried:

  • I tried adding buttons directly into the code, inserting them into the parent of the createButtonsForButtonBar. Result: Buttons won't get displayed.
  • I tried modifying the default buttons, even making defaultButton false didn't help.

The question:
How do I make the JFace Dialogs buttons useful?
Either

2

2 Answers

4
votes

It is not usual to override createButtonsForButtonBar, the default is usually fine unless you want to add more buttons or stop OK or Cancel being created.

If you want to do something when OK is pressed then override okPressed(), for cancel override cancelPressed() in both cases the super method should be called in the override.

0
votes

I've managed to use that method and no objects are disposed. You have to first call

super.createButtonsForButtonBar(parent);

Also the method okPressed has to be overriden and empty:

@Override
protected void okPressed() {
}

Then you can get the buttons with:

Button cancel = getButton(IDialogConstants.CANCEL_ID);

Button ok = getButton(IDialogConstants.OK_ID);

now you can add your own selectionListener