Writing a JavaFX PDF Viewer plugin for Netbeans – 2. Creating a plugin and adding an Action

Introduction

In part 1 we introduced the idea of plugins. In this section, we are going to dive straight in and create a plugin. We will need to assume you have some familiarity with Java as we go along.

1. Start NetBeans

Run NetBeans. I will be using my Mac (and I have added some tooltips to my menu bar) with the dark theme so you may find some things different on your machine. The ‘what’s New’ is one of my favourite features in NetBeans and the tutorials and articles are constantly being updated with new material. Notice the file menu at the top left.

Startup Netbeans

2. Create a new project

Select File-New Project and select NetBeans modules. Choose the Netbeans module. You can also see the options to create an application to use the NetBeans platform. Click on Next to continue

2. new projectThe New Project options shows all the different types of projects NetBeans can handle (and will also build examples with sample source code), so it is well worth coming back to look at later.

3. Set the project Name

Add a name for the project in the top box – choose something meaningful. Click on Next

3. Set project name

 4. Set a codebase

If you already have Java packages, you may want to use that. We will be using our Jpedal code so we will put a netbeans package in there. Whatever you type, stick to lower case (No CaPiTaLiSaTIon). Click on finish

4. Set a codebase

5. Check project completed.

You should now see your project in the NetBeans projects list on the left. If you do, Congratulations – you have created your first project.

new project

6. Add an Action

NetBeans includes a large amount of features so that you can quickly put together the skeleton for your application. So let us introduce that. Select the new NetBeans project and press your menu button. We will create an Action so highlight and select.

new action

7. Make action always available

You can choose whether this action is always available or only sometimes. We want to make it permanently available so just accept defaults.

action type

8. Select how user can use Action

An action can appear as a menu option, a toolbar icon and have a keyboard shortcut. You can also add it into a Category or create a new one. I recommend you see if it fits into an existing category first. All these options are setup from on this page (with minimal coding from you).

menu options

9. Link the action

Lastly we need to link the Action to a Java class which NetBeans will run when the Action is selected. This will create the Java class.

link action

 10. Review Action

You should now find NetBeans has created a new class which will be called when your Action is called.

new action code

 11. Running the code

It is time to run the code for the first time. If you click on the Green Arrow on the toolbar, NetBeans will run your plugin and open a second copy of NetBeans with the plugin. You will see our new Action item on the menu. It does not do anything at the moment – that will happen in the next part…

plugin

Click here for the next article in the series.

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 (TwitterFacebook and Google+) or the  Blog RSS.

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>