Archive for the ‘Toolbar’ Category

Recipe 13: Customize the menu and the toolbar(s)

March 4, 2014 Leave a comment


How can I customize the menu and the toolbar(s) of my RCP application?


Each module contains a layer.xml file which is something like a registry of the module. It contains information about the windows, menus, toolbars, actions etc. of the module. The RCP combines all layer.xml files of all modules to create the final application layout. Without getting into too much detail, you can display layer.xml of  a module by right-clicking on it and selecting: New | Other | Module Development | XML Layer. Then, if you expand the Imporant Files menu you see an XML Layer node which contains two subnodes: <this layer> and <this layer in context>. The first contains the menus, actions etc. of the current module (local registry) while the second is the global registry (of the application).

By right clicking, e.g. on a menu item, you have actions like Delete, Rename, New etc. which you can use to customise the menus according to your needs. Similar case for toolbars, actions etc.

Categories: Toolbar

Recipe 3: ToolBar

February 12, 2011 Leave a comment

How do I display a toolbar in Netbeans RCP?

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 {
   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:
 <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"/>
<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"/>

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

Categories: Toolbar