Ernest Duodu

Ernest is a developer at IDRSolutions. He focuses mainly on our JavaFX PDF Viewer implementation. He was a speaker at JavaOne 2014, where he did a joint session titled “Lessons learnt developing a NetBeans PDF viewer plugin in JavaFX”. Aside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.

Writing a JavaFX PDF Viewer plugin for Netbeans – 11. Creating a Submenu for our plugin in the NetBeans platform

1 min read

Introduction

In the previous article we introduced a callback object, which allows us to callback to NetBeans and update it. Now we want to create a submenu with three actions that will give us the option to choose from our Base ViewrFX, Open ViewerFX and External ViewerFX.

Creating the Submenu

Step 1. Create a NetBeans Module and an Action. NetBeans has this beautiful built-in wizards for creating Actions and Topcomponents. We will use the action wizard to create our submenu.

Screen Shot 2014-11-29 at 13.32.13
If you want a step-by-step tutorial of creating a NetBeans Module, Action and TopComponents click here to read our ‘Writing a JavaFX PDF Viewer plugin for Netbeans series‘ which takes you through the complete process of creating a plugin for the NetBeans Platform.

Step 2. Adding More Actions. You will have to create one or more actions. This depends on the number of menu items you want to have under the submenu. We will go ahead and create two more actions but before we do that, there’s one more thing we need to do.

Below is what the your generated action class should look like.

Screen Shot 2014-11-29 at 13.28.03
Currently our action is in the Menu/File folder .We need to add a new folder(submenu) to the ActionReference path so we can group our actions there. We will call the folder PDF Viewer.

Screen Shot 2014-11-29 at 13.42.06
We can now go ahead and create the other actions but before we do that lets do a clean and build on our module so it picks up the new folder we have created.

Because we’ve done a clean and build, this time we will do something slightly different when creating new actions using the action wizard. In the GUI Registration, we need to select File | PDF Viewer under the Menu drop down option.

Screen Shot 2014-11-29 at 14.00.49
 

Once you have created all the actions, we are in the position to run and test our new feature.

 

Screen Shot 2014-11-29 at 14.41.38
Screen Shot 2014-11-29 at 15.07.41
Now we have our PDF Viewer submenu appearing at the very top of the File menu option. To move this down, we have to do edit the layer.xml file. The layer.xml is the plugin’s configuration file . To access layer.xml, we will use the NetBeans builtin wizard to create one.

Screen Shot 2014-11-29 at 15.11.28
Screen Shot 2014-11-29 at 15.28.39
now add the code below to the layer.xml file

<filesystem>

 <folder name="Menu">
        <folder name="File">
            <folder name="PDF Viewer">
                <attr intvalue="1000" name="position"/>
            </folder>
        </folder>
 </folder>
</filesystem>

Screen Shot 2014-11-29 at 15.28.59
Once this is done, do a clean and build on the plugin and run it. Hope this helps

Screen Shot 2014-12-01 at 21.43.20
This post is part of our “NetBeans article Index” series. In these articles, we aim to explore NetBeans in different ways, from useful hint and tips, to our how-to’s, experiences and usage of the NetBeans IDE.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Ernest Duodu

Ernest is a developer at IDRSolutions. He focuses mainly on our JavaFX PDF Viewer implementation. He was a speaker at JavaOne 2014, where he did a joint session titled “Lessons learnt developing a NetBeans PDF viewer plugin in JavaFX”. Aside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.

Key Takeaways from Apache NetBeans Day UK

Apache NetBeans Day 2018 has come and gone. Whether you attended, watched it live or missed the event – we will take this opportunity...
Ovidijus Okinskas
2 min read

Leave a Reply

Your email address will not be published. Required fields are marked *