How to create button with icon

Answered

Dear all,

I'm developing a plug-in. I want to use icon buttons similar to idea's run and debug, but I don't know how to create it.

I want the effect

Current effect:Use JButton to created.

Thanks a lot.

0
8 comments

James,

Using UI Inspector you can check the exact classes related to any UI element in the IDE.

Thanks to that tool, we can quickly check, that the button's superclass is ActionButton.

0
 
I got it! Thanks Jakub. :D
0

Hello Jakub, I've added ActionButton according to the document you provided, but there's a small problem. ActionButton.MySeparator is private。 How can I add it? I can't use it directly

 

0

Yes, I've tried it. I think it's my wrong usage.

How to use it? Do you have any examples?

0

Got it, Thank you! 

By the way, I also sent you a separate email, if you have time, please have a look, there are some questions I hope you can answer! 

This email address: chesterccw@163.com

It was sent on August 3, China time UTF-8 TimeZone.

Provide this information so that you can find it easily.

Thank you very much.

0

I just referred to it PropertyTablePanel.java Changed my code, but found that there is still no Separator

This is part of my code

···

DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new MyButtonActions.PrevAction());
actionGroup.add(new MyButtonActions.NextAction());
actionGroup.addSeparator();
actionGroup.add(new MyButtonActions.ReloadAction());

@NotNull
AnAction[] myActions = actionGroup.getChildren(null);
for (AnAction action : myActions) {
if (action instanceof Separator) {
continue;
}
if(StrUtil.isEmpty(action.getTemplateText())){
continue;
}
Presentation presentation = PresentationUtil.getPresentation(action.getTemplateText());
ActionButton button = new ActionButton(action, presentation, ActionPlaces.UNKNOWN,
ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
operationPanel.add(button);
presentation.putClientProperty(BUTTON_KEY, button);
}
box.add(operationPanel);

···

I added a divider after the second icon

This is the display. It doesn't seem to work

0

Please sign in to leave a comment.