Quick Tip: Adding a Separator to a Toolbar

Sometimes it is useful to be able to visually separate groups of buttons on the main application toolbar. However, the NetBeans Platform doesn’t add separators to the toolbar by default as it is able to for the menubar. When I recently saw the question being posed again, I decided that it is time to find a way to accomplish this. And the key was in fact the NetBeans IDE 7.2 Plugin Quick Start tutorial. That tutorial describes how you can add other components besides buttons to the toolbar.

I followed the tutorial, but I didn’t create a panel. Instead I implemented the getToolbarPresenter() as follows:

public Component getToolbarPresenter() {
    JSeparator separator = new JSeparator();
    return separator;

That is it. Now I have a separator between two of the buttons on the toolbar.

Separator on the toolbar
Separator on the toolbar

Leave a Comment