Getting downward arrow in the toolbar button with dropdown menu

I wanted to create a toolbar button similar to debug or profiler button in NetBeans 6.0 IDE as in the image below.

This image shows the ‘debug project’ and ‘profile project’ with a small downward arrow that shows the user clearly that this is a button with a dropdown menu attached to it. To create a toolbar button with drop down menu, I followed the NetBeans DeveloperFAQ wiki which explains how to add dropdown to a toolbar button.

But the wiki help did not resulted in the purpose visually, although it helped me to put up a JToggle Button with attached drop down menu shown in the following images:

There’s clearly no visual hint, unless clicked on the toolbar button. So I decided to look further into the source code. I failed to look up the ‘debug project’ toolbar button code (I couldn’t find it in Java or Java/j2se modules), however, ‘profile project’ was easily visible. The class which creates this ‘profile project’ toolbar button is The getToolbarPresenter() has an interesting code to create that small arrow..

JButton button = DropDownButtonFactory.createDropDownButton(
                new ImageIcon(
                new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)),
Actions.connect(button, defaultAction);

toolbarPresenter = button;

So instead of creating a JToggleButton, it creates a normal button with a predefined image as the button icon. I think, the Actions.connect() will combine the button with the current action (visually I guess). Its really nice and handy trick to get the visual hint. Following images show the result.


One thought on “Getting downward arrow in the toolbar button with dropdown menu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s