Monday Feb 24, 2014

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.
@OnShowing
public class Startable implements Runnable {
    @Override
    public void run() {
        addToMainWindow();
    }
    public void addToMainWindow() {
        Frame mainWindow = WindowManager.getDefault().getMainWindow();
        Container contentPane = ((JRootPane) mainWindow.getComponents()[0]).getContentPane();
        JToolBar toolbar = new JToolBar();
        toolbar.setFloatable(false);
        toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.Y_AXIS));
        addButtons(toolbar);
        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());
            panel.add(button);
        }
    }
}

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.

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
« February 2014 »
SunMonTueWedThuFriSat
      
8
9
15
16
19
22
23
27
 
       
Today