Ordering of NetBeans Platform Menu/Toolbar Positions

Since there's no annotation for setting the position of a menu/toolbar (but only for items within them), here's a quick and easy way to do it by combining a layer file with the standard annorations:

<folder name="Menu">
    <folder name="Analyzers">
        <attr intvalue="300" name="position"/>

And now that the menu position is set, you can use the annotations exactly as before:

    category = "Tools",
id = "de.damaico.connection.analyzer.AnalyzeConnectionsActionListener")
    iconBase = "de/damaico/connection/analyzer/customer.png",
displayName = "#CTL_AnalyzeConnectionsActionListener")
    @ActionReference(path = "Menu/Analyzers", position = 0),
    @ActionReference(path = "Toolbars/Analyzers", position = 300)
@Messages("CTL_AnalyzeConnectionsActionListener=Analyze Connections")
public final class AnalyzeConnectionsActionListener implements ActionListener {

I.e., thanks to this tip (from Benno Markiewicz from Leipzig), you get the best of both worlds.

There's also a related patch in Issuezilla by Ernest Lotter. The patch creates a new annotation for registering menu positions:



would like to see the issues fixed:http://tomaszdziurko.pl/2010/04/my-first-tdd-or-why-netbeans-sucks/#more-225

Posted by guest on September 22, 2012 at 09:54 AM PDT #

"Hello, good evening. Would I need to create a new layer.xml file for this? I asked since everything in the build folder is recreated for clean and build and without cleaning I am still not able to see any form of changes."

Posted by guest on June 26, 2013 at 10:20 PM PDT #

Yes, you need to create your own layer.xml file for this.

Posted by Geertjan on June 26, 2013 at 11:24 PM PDT #

OK, thanks for the clarification.

Posted by Winnifred777 on June 27, 2013 at 09:51 AM PDT #

This is a good tip. Glad I found it. However I cannot figure out how to find out what's the position of the standard menu items so that I know what intvalue to choose for my new top-level menu. Right now I'm doing trial-and-error.

Posted by PeterH on October 01, 2014 at 02:06 PM PDT #

As a follow-up to my previous posting here are the position numbers that I've found by looking in the NB source code:

File menu: 100
Edit menu: 200
View menu: ?
GoTo menu: 400
Tools menu: 1000
Window menu: ?
Help menu: 1300

Posted by PeterH on October 01, 2014 at 02:21 PM PDT #

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.


« June 2016