Tip: How to Create Submenus on the NetBeans Platform
Join the DZone community and get the full member experience.
Join For FreeThis tip shows the way I usually create an action for a NetBeans Platform application and then include it into a submenu.
- Create
a new module, then use the Action wizard to create my DemoAction.
- The first panel asks for the type of Action, I leave Always Enabled
selected. In the next panels, I fill the forms with all required data, as shown below:
- Nothing
new, as you can see. And then let's tweak the layer.xml file entries that were created by the wizard shown above. This is what was generated:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE
filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN"
"http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
<folder name="Actions">
<folder name="Edit">
<file name="org-casaburo-submenuDemo-DemoAction.instance">
<attr name="delegate" newvalue="org.casaburo.submenuDemo.DemoAction"/>
<attr name="displayName" bundlevalue="org.casaburo.submenuDemo.Bundle#CTL_DemoAction"/>
<attr name="iconBase" stringvalue="org/casaburo/submenuDemo/add.png"/>
<attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
<attr name="noIconInMenu" boolvalue="false"/>
</file>
</folder>
</folder>
<folder name="Menu">
<folder name="Edit">
<file name="org-casaburo-submenuDemo-DemoAction.shadow">
<attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
<attr name="position" intvalue="100"/>
</file>
</folder>
</folder>
<folder name="Toolbars">
<folder name="File">
<file name="org-casaburo-submenuDemo-DemoAction.shadow">
<attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
<attr name="position" intvalue="0"/>
</file>
</folder>
</folder>
</filesystem>Now, let's say I want to place my Demo Action menu item under "My Submenu". I modify the layer.xml as below (notice the lines 20 to 25 below):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN"
"http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
<folder name="Actions">
<folder name="Edit">
<file name="org-casaburo-submenuDemo-DemoAction.instance">
<attr name="delegate" newvalue="org.casaburo.submenuDemo.DemoAction"/>
<attr name="displayName" bundlevalue="org.casaburo.submenuDemo.Bundle#CTL_DemoAction"/>
<attr name="iconBase" stringvalue="org/casaburo/submenuDemo/add.png"/>
<attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
<attr name="noIconInMenu" boolvalue="false"/>
</file>
</folder>
</folder>
<folder name="Menu">
<folder name="Edit">
<folder name="My Submenu">
<file name="org-casaburo-submenuDemo-DemoAction.shadow">
<attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
<attr name="position" intvalue="100"/>
</file>
</folder>
</folder>
</folder>
<folder name="Toolbars">
<folder name="File">
<file name="org-casaburo-submenuDemo-DemoAction.shadow">
<attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
<attr name="position" intvalue="0"/>
</file>
</folder>
</folder>
</filesystem>And this is the result:
That's all!
NetBeans
Opinions expressed by DZone contributors are their own.
Trending
-
Microservices With Apache Camel and Quarkus (Part 2)
-
Health Check Response Format for HTTP APIs
-
What ChatGPT Needs Is Context
-
Transactional Outbox Patterns Step by Step With Spring and Kotlin
Comments