Geertjan's Blog

  • February 24, 2014

Of Toolbars and Banners

Geertjan Wielenga
Product Manager
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.

Join the discussion

Comments ( 3 )
  • guest Monday, February 24, 2014

    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.

  • Peter Hansson Monday, February 24, 2014

    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/

  • Trey Tuesday, February 25, 2014

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

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.