SWT: how to create a regular button from an action

I need a line Buttonfrom IAction. Do I have to do this myself or is there already something in JFace that I can reuse? Please note: I need a button instance because I want to make it the default button in the dialog box.

Since new ActionContributionItem(action).fill(parent);I can't seem to get a button instance.

+3
source share
2 answers

After fill(parent)I think you can call parent.getChildren (). I expect the new button to be the last entry in the returned control []. Therefore:

Control kids[] = parent.getChildren();

if (kids != null && kids.length != 0) {
  getShell().setDefaultButton( (Button)kids[kids.length - 1] );

}

, , ... .

+1

, getWidget() ActionContributionItem, Button, ActionContributionItem.

    ActionContributionItem aci = new ActionContributionItem(action);
    ai.fill(parent);
    Button widget = (Button) ai.getWidget();
+3

Source: https://habr.com/ru/post/1779744/


All Articles