Home > Toolbar > Recipe 3: ToolBar

Recipe 3: ToolBar

Problem:
How do I display a toolbar in Netbeans RCP?

Solution:
To display a ToolBar in Netbeans RCP, a class must implement the Presenter.Toolbar interface:

package my.package.toolbar;
public class AToolBar implements Presenter.Toolbar {
   @Override
   public Component getToolbarPresenter() {
       return aComponent;            // e.g. a JLabel, a JPanel etc.
   }
}
However, this is not enough. You need to edit layer.xml too like so:
<filesystem>
 <folder name="Actions">
  <folder name="View">
   <file name="my-package-toolbar-AToolBar.instance">
     <attr name="delegate" newvalue="my.package.toolbar.AToolBar"/>
     <!--attr name="displayName" bundlevalue="my.package.toolbar.Bundle#CTL_AToolBar"/-->
     <attr name="noIconInMenu" boolvalue="true"/>
   </file>
  </folder>
 </folder>
<folder name="Toolbars">
 <folder name="MyToolBar">
  <file name="my-package-toolbar-AToolBar.shadow">
    <attr name="originalFile" stringvalue="Actions/View/my-package-toolbar-AToolBar.instance"/>
    <attr name="position" intvalue="10"/>
   </file>
  </folder>
 </folder>
</filesystem>

You need to add your toolbar under <Toolbars> folder. Then you can declare the actual path to the class using <originalFile> attribute.

Advertisements
Categories: Toolbar
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: