How to add a "multi-button" in table's toolbar?

Answered

I would like to add a "multi-button" in a table's toolbar. A "multi-button" like...

The "multi-button" should be added in a table's toolbar. Something like...

Does anybody know how to do this?

0
5 comments

Such "button" is created by implementing the DefaultActionGroup.

0

Jakub Chrzanowski I was using that, but when I add it to the ToolbarDecorator.setActionGroup, it was adding all the actions in the DefaultActionGroup 1 by 1. It wasn't grouping them into one "multi-button". Do I need to so anything else to make it a "multi-button"?

0

You have to set the popup flag to true.

0

I did that as well. Here's a snippet...

ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(tbl);
AnAction action1 = new DumbAwareAction(AllIcons.General.ArrowUp) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {

}
};
AnAction action2 = new DumbAwareAction(AllIcons.General.ArrowDown) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {

}
};
AnAction action3 = new DumbAwareAction(AllIcons.General.ArrowRight) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {

}
};


DefaultActionGroup actionGroup1 = new DefaultActionGroup(action1, action2);
actionGroup1.getTemplatePresentation().setIcon(AllIcons.General.Add);
actionGroup1.setPopup(true);

DefaultActionGroup parentActionGroup = new DefaultActionGroup(actionGroup1, action3);
toolbarDecorator.setActionGroup(parentActionGroup);
pnlTbl.add(toolbarDecorator.createPanel());

And then here's the output...

If you'll notice, only the icon for the group is shown (I was expecting a multi-button).

0

So I found the right way to do this, thanks to the Slack channel.

  1. Create a custom AnActionButton.
  2. In the custom AnActionButton, use a JBPopup. You can create one using JBPopupFactory.

For the icon, you can use LayeredIcon to combine two icons. One for the icon you need and then AllIcons.General.Dropdown for the drop-down arrow.

And the correct term is actually drop-down button.

0

Please sign in to leave a comment.