Dave has posted 2 posts at DZone. View Full User Profile

Adding Quick Toolbars to Explorer Views

  • submit to reddit
Quick Toolbar in Explorer ViewThe Explorer View provided by NetBeans Platform is extremely useful and powerful. Often, I find that my applications will have several explorer views each with different modes (explorer, navigator, etc). The application will usually have menu items, toolbars on the top, and right-click options on the nodes in the explorer view. I have noticed that sometimes, it is not hard to get lost or even to intuitively know which global toolbar actions go with which explorer view (other than watching the enabled/disabled state toggle as I click the different nodes).  I came up with a quick method to remove some of the clutter from the global toolbar and more closely associate view-specific actions with the related explorer view.

In my applications, usually each explorer view belongs to its own module and therefore the actions offered by that module are only applicable to the view(s) that belong to that module. So moving these actions down to the relevant explorer view makes sense. Also, this relieves the user of the burden to surf through the potential myriad of global toolbar buttons to find the action for which he/she is looking. Since the user’s eyes are already focused in the explorer view, placing the actions in a toolbar within the view makes finding the actions easier and also reduces the distance that the user has to move the mouse to find the action. The image above illustrates the concept (the red outline has been added to draw the reader’s attention).

The implementation of this is fairly simple:

  1. In the TopComponent containing your Explorer view, place your view (e.g., BeanTreeView) in a JPanel and set the TopComponent’s layout to BorderLayout. Set the DIRECTION property of this JPanel to CENTER.

  2. Add JToolBar to your TopComponent. Set the DIRECTION property to SOUTH.

  3. Add actions to your module as needed either by editing the layer.xml file manually or using the New Action wizard.

For this example, we will assume that when you created your actions, you created a shadow entry in the global toolbar under “Toolbars/Widgets”.

<folder name="Toolbars">
<folder name="Widgets">
<file name="org-drx-modules-widgetview-actions-CreateWidgetAction.shadow">
<attr name="originalFile" stringvalue="Actions/Widgets/org-drx-modules-widgetview-actions-CreateWidgetAction.instance"/>

I added a method named initMyToolbar() to the TopComponent. This method finds all of the actions for Widget within the Toolbars folder and adds them to the JToolbar control.

public void initMyToolbar() {
List<? extends Action> alist = Utilities.actionsForPath("Toolbars/Widgets/");
for (Action action : alist) {

Invoke the initMyToolbar() method at the end of the constructor for the TopComponent containing the view and viola, functional toolbar buttons right next to the view itself. I typically set the floatable property of the JToolbar object to false so that the toolbar will stay in place, right next to the view to which it belongs.

From http://www.rigsby.org

Published at DZone with permission of its author, Dave Rigsby.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Claudio Rosati replied on Tue, 2010/09/07 - 2:04am

An hint that required an half a day before figure it out:

on MacOS X a toolbar created without the "editorToolbar" name will have button icons with the drop shadow under them (as in the main toolbar). Taht said, local toolbar must be created in tis way:

Toolbar toolbar = new Toolbar("editorToolbar", "Toolbar Display Name", false);

Matt Coleman replied on Mon, 2012/01/16 - 4:34am in response to: Claudio Rosati

thanks for sharing this Claudio especially on macOs X!! I really appreciate it web design buffalo

Mateo Gomez replied on Tue, 2012/01/17 - 1:24am

yes..this helps a lot Claudio..thanks again! mexican dessert recipes

Cata Nic replied on Fri, 2013/09/06 - 3:08am

 A toolbar like this one is a better way to improve your effectiveness. I think is a good idea to use this trick to all your products.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.