Adding toolbar buttons to my form

Does anyone know how i can add to a UI Designer a toolbar with icon buttons with same look&feel that the IDEA toolbar has ? With the light blue backgound color on hover and all.

Thanks.

4 comments
Comment actions Permalink

Hello Hugo,

HP> Does anyone know how i can add to a UI Designer a toolbar with icon
HP> buttons with same look&feel that the IDEA toolbar has ? With the
HP> light blue backgound color on hover and all.

- Add JComponent class to palette
- Add the JComponent to your form
- Set the "Custom Create" flag
- In the createUIComponents() method, create an ActionToolbar instance and
assign the value returned by ActionToolbar.getComponent() to the JComponent
field.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

I'm not sure how that solves my problem.

How do i initialize the JComponent ? That's where i add the buttons right ?

When i add a JButton to the JComponent i don't get the IDEA look&feel.

0
Comment actions Permalink

The JComponent is only a placeholder, you don't initialize it actually.

The solution of Dmitry looks something like this:

DefaultActionGroup actions = new DefaultActionGroup();
AnAction action = ...; // add your actions here, passing the appropriate icon
actions.add(action);
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actions, true);
yourComponent = toolbar.getComponent();

0
Comment actions Permalink

Hello Hugo,

HP> I'm not sure how that solves my problem.
HP>
HP> How do i initialize the JComponent ? That's where i add the buttons
HP> right ?
HP>
HP> When i add a JButton to the JComponent i don't get the IDEA
HP> look&feel.

You need to implement a class extending AnAction for each of the buttons
or other controls that you want to have on your toolbar, then create a DefaultActionGroup
and add the AnAction class instances to it, then use ActionManager.createActionToolbar()
to create the toolbar from the action group.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.