Home > NB Platform > Custom Toolbar Configuration

Custom Toolbar Configuration

In my first NetBeans Platform post I show you how you can change the default toolbar configuration of your NetBeans Platform application:

  • Change the default toolbar icon size to 16px
  • Right aligned toolbar
  • Non-floating toolbar
  • Create your own set of Toolbar configuration

After reading this article about general toolbar configurations and some investigation in the NetBeans Platform source code I found the solution for the items above. The improved DTD for toolbar configuration (version 1.1) introduced with NetBeans V6.7 allows you to use the new attributes “align” and “dragable”, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration PUBLIC "-//NetBeans IDE//DTD toolbar 1.1//EN"
      <Toolbar name="File" visible="true" />
      <Toolbar name="Clipboard" visible="false"/>
      <Toolbar name="UndoRedo" visible="false"/>
      <Toolbar name="Memory" visible="true" draggable="false" align="right"/>
      <Toolbar name="Picture" visible="true" draggable="false" align="right"/>

Overwrite the default toolbar configuration in the layer.xml:

<!-- http://wiki.netbeans.org/DevFaqHideShowToolbar -->
<!-- http://blogs.sun.com/geertjan/entry/toolbar_configurations -->
<folder name="Toolbars">
   <file name="MyToolbars.xml" url="res/MyToolbars.xml">
      <attr name="position" intvalue="100"/>

A NetBeans Platform application comes with the two toolbar sets:

  • Default
  • Debugging

In the example configuration above I created a new one named “MyToolbars”.

Now I want “MyToolbars” as my default toolbar configuration. Additionally I need to have 16px icons as default.
To achieve this, write a custom Window Manager Properties file:

<!-- File: res/windowManager.xml -->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE windowmanager PUBLIC
          "-//NetBeans//DTD Window Manager Properties 2.1//EN"

<windowmanager version="2.1">
      <joined-properties centered-horizontally="true" centered-vertically="true"
                           relative-width="0.9" relative-height="0.9" />
      <separated-properties centered-horizontally="true" relative-y="0.1"
                           relative-width="0.8" relative-height="0.08" />
   <editor-area state="joined">
         <path orientation="horizontal" number="60" weight="0.7" />
         <path orientation="vertical" number="40" weight="0.7" />
         <path orientation="horizontal" number="40" weight="0.7" />
      <relative-bounds x="33" y="24" width="42" height="44"/>
   <screen width="1280" height="1024" />
   <active-mode name="explorer" />
   <maximized-mode name="" />
   <toolbar configuration="MyToolbars" preferred-icon-size="16" />

… and registered in the layer.xml:

<folder name="Windows2">          
   <file name="WindowManager.wswmgr" url="res/windowManager.xml" />
Categories: NB Platform Tags: ,
  1. Sam
    2010-12-3 at 15:39

    Dear anchialas,

    I tried to make some of my toolbars to be dynamic based on the topComponent’s existence or absence. I created my own customToolbarConfig.xml and change the default Standard.xml to change the visibility of some of my custom-made toolbars to be false so i can let em visible after the required components being active or inactive. My standard.xml file is defined as follows (as if i have a custom created toolbar named MyToolbar) :

    The problem : First time it works some how ok ( sometimes ). By using ToolbarPool.getDefault().setConfiguration(“Standard”);
    in the componentactivate or componentdeactivate methods of myTopComponent, i can control the visibility or invisibility of my targeted toolbars.
    After quiting the application and re executing it, it seems the platform doesn’t following the standard.xml i have created, and reading from some plain or default standard configurations. It only shows FILE , UNDO/REDO and MYTOOLBAR which are not the things i have defined in my standard.xml.

    the result is the same if create a new toolbar which i wanted to be invisible by changing the standard.xml. The platform doesn’t pay attention to the XML file and shows the newly created toolbar. Have you got any solutions or tips regarding this problem ?

    • 2010-12-17 at 15:09

      Hi Sam

      Thank you for reading my blog. I’ve found probably a solution for your problem, but it’s quite a hack. For programatically hide and show a toolbar you can write:

      Toolbar toolbar = ToolbarPool.getDefault().findToolbar( “toolbarName”);

      The drawback is, that the visible state of the toolbar will not be propagated to the toolbar context menu actions.
      Maybe I found a better solution to achieve this… Keep reading my blog!

  2. Sam
    2010-12-17 at 15:42

    Thank you for that …

  3. 2012-03-21 at 12:34

    I am new in development field; I try to develop custom toolbar from your blog and success in custom toolbar for my project.

  4. 2012-05-31 at 13:46

    You can save changes that you make to the toolbars in custom Toolbar Configuration. Once created, Toolbar Configurations can be backed up, transferred to different computers, and shared with other program users.

  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 )

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

%d bloggers like this: