This document takes you through the basics of using NetBeans IDE to develop NetBeans plug-in modules. You develop NetBeans plug-in modules for one of two reasons:
Mainly the first scenario above is covered in this introduction guide, although the principles addressed here also apply to the second. However, note that the Introduction to Rich-Client Application Development is a better tutorial for you if you want to learn about developing applications on top of the NetBeans Platform.
This tutorial is designed to get you going as quickly as possible. You will create and install a simple NetBeans plug-in module. The plug-in module will add a new menu item and a toolbar button to the IDE. When you select the menu item or toolbar button, a DialogDisplayer, provided by the NetBeans APIs, with the text "I'm plugged in!" will be displayed.
The following topics are covered below:
This tutorial can be completed in 20 minutes.
For more information on NetBeans plug-in modules, see the NetBeans Development Project home on the NetBeans website. If you have questions, visit the NetBeans Developer FAQ page.
Before you start writing the plug-in module, you have to make sure you have all of the necessary software and that your project is set up correctly. NetBeans provides a wizard that sets up all the basic files needed for a plug-in module.
Before you begin, you need to install the following software on your computer:
NetBeans plug-in module support provides three project types:
Click Finish. The IDE creates the MyFirstModule project. The project contains all of your sources and project metadata, such as the project's Ant build script. The project opens in the IDE. You can view its logical structure in the Projects window (Ctrl-1) and its file structure in the Files window (Ctrl-2):
In addition to the localizing bundle and the XML layer, the project also includes the following important files:
You will not need to modify any of these files during this tutorial. Note that the important files listed above are the logical views of the following files in the Files window: manifest.mf, build.xml, nbproject/project.xml, nbproject/platform.properties, and nbproject/private/platform-private.properties, respectively.
You use the NetBeans plug-in module file templates to create the basis of the module's functionality. When you use a file template, the IDE registers the item that you create in the layer.xml file. After using a wizard to create the file template, you use the NetBeans API List to continue developing the module.
Select Separator Before and Separator After in the Global Menu Item section.
You should now see the following:
Note the following about the sections in the GUI Registration panel:
Click Next.
enterprise2\jakarta-tomcat-5.5.9\server\webapps\admin\images
The IDE creates MyFirstAction.java in org.myorg.myfirstmodule and opens it in the Source Editor. This is what you should see (click on the links to see the related NetBeans API Javadoc):
package org.myorg.myfirstmodule; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; public final class MyFirstAction extends CallableSystemAction { public void performAction() { // TODO implement action body } public String getName() { return "My First Action"; } protected String iconResource() { return "org/myorg/myfirstmodule/Groups.gif"; } public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } protected boolean asynchronous() { return false; } }
As specified in the GUI Registration panel, the IDE registers the action class as a menu item and as a toolbar button in the layer.xml file:
<filesystem> <folder name="Actions"> <folder name="Tools"> <file name="org-myorg-myfirstmodule-MyFirstAction.instance"> <attr name="instanceClass" stringvalue="org.myorg.myfirstmodule.MyFirstAction"/> </file> </folder> </folder> <folder name="Menu"> <folder name="Tools"> <attr name="org-openide-actions-ToolsAction.instance /org-myorg-myfirstmodule-MyFirstAction.shadow" boolvalue="true"/> <file name="org-myorg-myfirstmodule-MyFirstAction.shadow"> <attr name="originalFile" stringvalue="Actions/Tools/org-myorg-myfirstmodule-MyFirstAction.instance"/> </file> <attr name="org-myorg-myfirstmodule-MyFirstAction.shadow/Separator1.instance" boolvalue="true"/> </folder> </folder> <folder name="Toolbars"> <folder name="Build"> <attr name="org-netbeans-modules-project-ui-RunMainProject.shadow /org-myorg-myfirstmodule-MyFirstAction.shadow" boolvalue="true"/> <file name="org-myorg-myfirstmodule-MyFirstAction.shadow"> <attr name="originalFile" stringvalue="Actions/Tools/org-myorg-myfirstmodule-MyFirstAction.instance"/> </file> <attr name="org-myorg-myfirstmodule-MyFirstAction.shadow /org-netbeans-modules-project-ui-DebugMainProject.shadow" boolvalue="true"/> </folder> </folder> </filesystem>
public void performAction() { String msg = "I'm plugged in!"; NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(d); }
The line with the calls to NotifyDescriptor and DialogDisplayer are underlined and marked as an error, similar to the following illustration. This is because the related packages have not been declared yet. You will declare them in the next step.
Click OK. The Dialogs API is added to the Module Dependencies list. Click OK to confirm and exit the Project Properties dialog box.
import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor;
The plug-in module is now complete. Next, you need to install and use it.
The IDE uses an Ant build script to build and install your plug-in module. The build script is created for you when you create the plug-in module project.
The plug-in module is built and installed in the target platform. The target platform is set in Tools > NetBeans Platform Manager. The target platform opens so that you can try out your new plug-in module. The default target IDE or Platform is the installation used by the current instance of the development IDE.
For more advanced tutorials, see the following resources:
For more information about creating and developing NetBeans plug-in modules, see the following resources: