NetBeans Modules for Dummies (Part 2)

One way to learn about writing NetBeans Modules (NBMs) is to look at how others do it. Take, for example, Sandip Chitale's Module Explorer. It shows you all the NBMs installed in the IDE, together with a dependency graph and details tab (click to enlarge):

When you open this NBM's source in the IDE, the structure in the Files window is as follows:

From yesterday's blog entry, we know that the file that hooks the Action ( in the screenshot above) to the IDE is the layer.xml file in the resources folder. However, this one is more interesting than the one from yesterday. Yesterday's layer.xml only provided for a menu with a submenu containing a menu item. Sandip's module is more ambitious, so its layer.xml is more complex. Here it is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem
 PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN"

    <folder name="Menu">
        <folder name="Tools">
             <file name="ShowModuleExplorerAction.shadow">
                <attr name="originalFile" 
    <folder name="Toolbars">
        <folder name="Tools">
            <file name="ShowModuleExplorerAction.shadow">
                <attr name="originalFile" 
   <folder name="Actions">
        <folder name="File">
            <file name="org.netbeans.modules.moduleexplorer.ShowModuleExplorerAction.instance"/>


The entries in Sandip's layer.xml are as follows:

  • Menu. This entry hooks the Action to the IDE's Tools menu:

  • Toolbars. This entry hooks the Action to the IDE's toolbar:

  • Actions. This entry hooks the Action to the File section of the Actions list in the Keyboard Shortcuts dialog box:

    The Keyboard Shortcuts dialog box is found under the IDE's Tools menu. Once you've hooked an Action to the Keyboard Shortcuts dialog box, you can configure the keystrokes that you use to invoke it. To add the Action to the Shortcuts List in the Keyboard Shortcuts dialog box, you would create an entry called Shortcuts to the layer.xml.

And this is Sandip's Action, which extends CallableSystemAction:

public class ShowModuleExplorerAction extends CallableSystemAction {
    public void performAction() {        
        JDialog dialog = new JDialog(WindowManager.getDefault().getMainWindow(), "Module Explorer", true);
        dialog.setContentPane(new ModulesPanel());
        dialog.setSize(1600, 1000);;
    public String getName() {
        return NbBundle.getMessage( ShowModuleExplorerAction.class, "LBL_ShowModuleExplorerAction" ); //NOI18N
    protected String iconResource() {
        return "org/netbeans/modules/moduleexplorer/resources/module.gif"; //NOI18N
    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;
    public boolean asynchronous() {
        return false;


Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« August 2015