Java/RCP – okPressed in JFace dialog

Veröffentlicht von

Sometimes JFace and RCP are not straightforward. At least not for me.

For example the JFace dialog:

It features an OK and Cancel button by default. If you want to do something when the user clicks the OK button, for example save the values from control elements to variables, you can overwrite the "okPressed" method:

    @Override
    protected void okPressed() {
        nameString = textBoxName.getText();
        super.okPressed();
    }

When the OK button is pressed, the "okPressed" method is executed. The "open" method of the dialog returns IDialogConstants.OK_ID in that case (instead of SWT.OK).

Of course there is also a "cancelPressed" method for the Cancel button

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert