Yet Another Blog About How Easy It
Is To Write Plug-in Modules For NetBeans.
If you are tired of reading about how easy it is to create plug-in modules for NetBeans,
then do not read this blog entry.
Yes, this topic has been discussed quite a bit. It has even turned Geertjan Wielenga into
celebrity. If you go to Google
and just type in "Geertjan" then you can
just click the "I'm Feeling Lucky" button because
Geertjan's blog is always at the top of that list.
He and Roumen
are becoming known by just one name, sort of like Cher,
There are also folks blogging about this who are not
Sun employees. To take just one example,
take a look at this entry
by Tomohiro Iizuka.
Into this whirlwind of activity I would like
to submit my small humble contribution, which boils down to this: if even I can create a
plug-in module for NetBeans then anyone can. :-)
Here's my situation. I frequently need to create HTML (for blog entries, tutorials, etc.).
I never learned how to use one of those fancy HTML editing tools so I use the HTML editor
that is included in the NetBeans IDE.
It's not WYSIWYG, but it has what I need: syntax
highlighting, code completion, indentation, etc. What it does not have is an easy way to
create links. Those of you who are familiar with the HTML editor might say, "But what about
the HTML Palette?" Fair enough. But I don't like to take my hands off the keyboard. Also,
I prefer to write the entire document and then go back and insert the anchor tags around
What I typically do is open a browser and find the URL for the link I want to create. I copy it
to the clipboard and then come back over to the IDE. I paste the URL into an anchor tag. Then
repeat until done. I could define a keystroke macro to help out, but I want something a bit
more powerful. I want to select the words for the link:
And then have a keyboard shortcut that will take the contents of the clipboard and
put it into the href attribute for an anchor tag, with the closing tag at the end of the selection:
I don't know how to do that with a keystroke macro, because I would need to determine
the beginning and ending of the current text selection. But it's easy enough to do this
with a simple plug-in module.
The starting place for this adventure was Geertjan's excellent
Quick Start Guide. You end
up with a plug-in module that doesn't do much, but it can be used as a template. I then moved
the Editor Extension Module tutorial,
which taught me the basics of how to extend one of
the IDE's editors. At this point I was able to create a plug-in module that had an Action.
But how do I fill in the logic to accomplish what I want? In other words, which
do I use, and how?
I was reminded of a conversation that
Chuk Munn Lee and
I had with an attendee of
NetBeans Day Singapore.
Chuk had done a demo
of NetBeans module development and the question from the attendee was basically, "This
is great and everything, but after the wizard does all that stuff for you, how do figure out
which APIs to use?" Chuk had a good answer: "Read the
for the NetBeans IDE. It's
pretty well organized and straightforward. Find the type of functionality you want and
then go see how it is accomplished in the source."
In addition to the source for the IDE there are other resources. Geertjan's
growing list of tutorials
both good starting points.
In addition to those,
NetBeans: The Definitive Guide
is available online; the experts tell
me that most of its information about module development is still valid. Finally, there
firstname.lastname@example.org email list which is very active.
For my little plug-in module it was not necessary to look very far for help. The prolific
Sandip Chitale created a module that he calls
It adds functionality to an editor and
in general looked like something from which I could learn some things.
The source code is in /contrib so
I checked it out of CVS
and started wandering through it. And sure enough, he had several
snippets of code that I could use. By using what he had and then
adding three lines of my own code I had the
The only thing missing was a keyboard shortcut. Sandip pointed me to the relevant
entries in the FAQ (here
which were contributed by Tim Boudreau and
Tom Wheeler. I edited
my layer.xml by following those instructions (and yes Tim, I used an "O" to indicate Alt :-) ). I now have a new Link Inserter entry in
the context menu of the HTML editor:
I prefer to use the keyboard shortcut, but the context menu entry is there should I ever
Want to learn even more and ask questions while doing it? If you live in northern California
or are planning to attend JavaOne, then come to
Tim Boudreau will be
teaching module development in the context of using the
NetBeans Platform as a base
for building rich client applications. Seats are limited, so register now. The event
is free and you do not have to be registered for JavaOne in order to attend. And as always,
there will be free prizes. :-)