Creating custom Toolbar

Hi,

I am trying to create a custom implementation of the FileHistoryPanel by extending PanelWithActionsAndCloseButton. I need a toolbar on this panel which has three buttons and one custom dropdown box. The buttons need to have specific icons.

How should I create this toolbar under the IntelliJ framework? Specifically
- Would it be ok if I use regular JButtons?
- How should I load the required icons? Would IconLoader do?
- How should I associate actions to these buttons? Should I extend AnAction and associate that?

thanks
dk

4 comments
Comment actions Permalink

Hello Dhwani,

PanelWithActionsAndCloseButton already supports a toolbar, so you don't need
to implement it at JButton level for yourself. Just create AnAction classes
for the buttons, and ComboBoxAction for the dropdown box. Then override addActionsTo()
method and add these actions to the group passed to the method.

Note that this class puts the toolbar on the left side, which may not be
appropriate for you if you need to place a dropdown box on the toolbar.

I am trying to create a custom implementation of the FileHistoryPanel
by extending PanelWithActionsAndCloseButton. I need a toolbar on this
panel which has three buttons and one custom dropdown box. The buttons
need to have specific icons.

How should I create this toolbar under the IntelliJ framework?
Specifically
- Would it be ok if I use regular JButtons?
- How should I load the required icons? Would IconLoader do?
- How should I associate actions to these buttons? Should I extend
AnAction and associate that?
thanks
dk

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

I had read in another post that we cannot add a dropdown to the default toolbar. Even other wise the method ActionManager.createActionToolbar(...) returns an ActionToolbar and this interface does not have any methods to add a component. Please let me know if I am missing something here.

That was the reason why I had created my own toolbar.

thanks in advance
Dhwani

0
Comment actions Permalink

Hello Dhwani,

I had read in another post that we cannot add a dropdown to the
default toolbar. Even other wise the method
ActionManager.createActionToolbar(...) returns an ActionToolbar and
this interface does not have any methods to add a component. Please
let me know if I am missing something here.


As I said in my previous post, in order to add a dropdown to a default toolbar,
use the ComboBoxAction class. You can look at the "Run" action in the IDEA
toolbar as evidence that it can be done. :)

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

Thanks. :) I tried out the approach you suggested and was able to add my actions to the default toolbar. I was even able to pull the toolbar up by using the following tweak. Hope it doesnt fail in any particular boundary case.

public MyFileHistoryPanel( ... ) {
....
init();

ActionToolbar actionToolbar = (ActionToolbar) this.getComponent(0);
actionToolbar.setOrientation(SwingConstants.HORIZONTAL);
remove(0);
add(actionToolbar.getComponent(), BorderLayout.PAGE_START);
}

Thanks again

dk

0

Please sign in to leave a comment.