Monday Jun 23, 2014

Floatable Toolbars on the NetBeans Platform

So you're creating your awesome application on the NetBeans Platform...

But... you want the toolbars to be floatable. 

Notice that above there are now suddenly new 'floatable' markers to the left of each toolbar, indicating that you can drag the toolbar out of the toolbar container, as has been done for two toolbars here:

Here's how:

import org.openide.awt.Toolbar;
import org.openide.awt.ToolbarPool;

public class Startable implements Runnable {
    public void run() {
        ToolbarPool tb = ToolbarPool.getDefault();
        Toolbar[] toolbars = tb.getToolbars();
        for (Toolbar toolbar : toolbars) {

Note that this only works, to my knowledge anyway, with Nimbus. At least, I tried with Metal and I didn't see the handles for dragging and hence probably the same is true for other look and feels. To return a toolbar to the toolbar container, click the "x", i.e., the close button top left in the dialog that contains it. Also, there's a "Reset Toolbars" menu item in the toolbar which you probably want to remove/hide if you're using the solution above because it causes strange behavior in the above scenario.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« June 2014 »