Of Toolbars and Banners

From some code by Djamel Torche, here's how to create a toolbar along the left side of the NetBeans Platform.
public class Startable implements Runnable {
    public void run() {
    public void addToMainWindow() {
        Frame mainWindow = WindowManager.getDefault().getMainWindow();
        Container contentPane = ((JRootPane) mainWindow.getComponents()[0]).getContentPane();
        JToolBar toolbar = new JToolBar();
        toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.Y_AXIS));
        toolbar.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        contentPane.add(BorderLayout.WEST, toolbar);
    private void addButtons(JToolBar panel) {
        for (Action a : Utilities.actionsForPath("Toolbars/Clipboard")) {
            JButton button = new JButton(a);
            Mnemonics.setLocalizedText(button, a.getValue(Action.NAME).toString());

And if you want a banner along the top of the NetBeans Platform, one that can't be moved, one that doesn't resize, one that can't be closed, simply use the code above and change BorderLayout.WEST to BorderLayout.NORTH. And/or change JToolBar to JPanel.


Mille grazie.

For reference: I've tested it out not with JToolbar but with a JPanel of my own and with BorderLayout.NORTH. The goal being to create a top banner.

Hermien blogs about this here: http://www.pellissier.co.za/hermien/?p=620

I've found that at least on Windows L&F you'll need to set aside 32 pixels minimum at the top of your custom JPanel. Otherwise the NB toolbar will overlap the visual elements in your JPanel. Also: don't bother to put a border around your container. It will look ugly because the top side of the border will always be "eaten" so better visually to leave it out completely.

Posted by guest on February 24, 2014 at 05:07 AM PST #

Last comment was by me as well. Didn't mean to be anonymous. :-)

Regarding horizontal banner: I've refined the method (so you don't have to worry about overlap size) and also added lots of explanatory screenshots. And also now a border has correct look.
Have a look here: http://netbeansscribbles.wordpress.com/2014/02/24/netbeans-platform-banner/

Posted by Peter Hansson on February 24, 2014 at 02:56 PM PST #

I wanna thank you for posting the article about setting Genymotion up to Netbeans. Great work!

Posted by Trey on February 24, 2014 at 05:35 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

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.


« November 2015