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;
import org.openide.windows.OnShowing;

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

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.

Comments:

Where are these imports? I do not find org.openide.awt.Toolbar or org.openide.awt.ToolbarPool in UI Utilities API in Netbeans 8.0

Posted by guest on July 03, 2014 at 10:21 AM PDT #

Found them, they are in the Datasystems API

Posted by Kevin Moore on July 03, 2014 at 10:26 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.

Search

Archives
« July 2015
SunMonTueWedThuFriSat
   
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today