Geertjan's Blog

  • September 20, 2012

Ordering of NetBeans Platform Menu/Toolbar Positions

Geertjan Wielenga
Product Manager

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:


Join the discussion

Comments ( 6 )
  • guest Saturday, September 22, 2012
  • guest Thursday, June 27, 2013

    "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."

  • Geertjan Thursday, June 27, 2013

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

  • Winnifred777 Thursday, June 27, 2013

    OK, thanks for the clarification.

  • PeterH Wednesday, October 1, 2014

    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.

  • PeterH Wednesday, October 1, 2014

    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

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