Netbeans have a modular architecture that permits plug and unplug functionalities easily using the Plugin Manager.
It’s also easy create new plugins using Netbeans itself.http://silveiraneto.net/wp-admin/media-upload.php?post_id=705&TB_iframe=true
1º Step: A new module.
Create a New Project clicking in File → New Project.
Figure 1. Creating a new project
In Categories select Netbeans Module and in Projects select Module.
Figure 2. Creating a new module.
Click in Next.
In the next screen you can choose your module name, like HelloYou. Leave the rest with the default values.
Figure 3. Naming the module.
Now you have to set up the package base name, something like org.yourorg.helloyou.
Figure 4. Package name.
Now you have an empty module, but we need some action.
2º Step: Some action.
Right click in your source package and click in New → Action.
Figure 5. Adding some action.
Now we’ll fill another wizard. The first screen is about Action Type. Leave all with the default values (the Always Enabled option) and click Next.
Figure 6. Filling the Action Type.
In the GUI Registration screen we can set where we want our action appears as an menu item. We chose Menu file and select Global Toolbar Button. In Toolbar select Build and in Position select Profile Main Project…- HERE. Click Next.
Figure 7. GUI Registration.
Now we will set up the screen Name, Icon and Location. In Class Name we choose HelloAction. Display Name is how the class will appear in the menu, so we can spaces. You should select an icon in dimensions of 16×16. In the same directory you can put to an icon in 24×24. If your 16×16 icon is named ball.png your 24×24 icon should be ball24.png. Doesn’t matter where is this icon, it’ll be automatically copied to the module directory. Now click Finish.
Figure 8. Name, Icon and Location.
I used an smile icon from the Pidgin Project.
After clicked in Finish your project will look like that:
Figure 9. Empty action.
At this point we can already test our module! For doing that right click in HelloYou (puzzle icon) and select Install/Reload in Target Platform. This will open a new instance of Netbeans with your module installed!
Figure 10. Install/Reload in target platform.
If everything goes alright you will see your icon in the toolbar.
Figure 11. Look! We got an plugin!
But if you click in the smile nothing happens. We have defined no action at all.
3º Step: Creating dependencies.
A module can have dependencies from others modules. When you try to install it, Netbeans will ask about install their modules dependencies. Is much like an Linux package system.
We can see and set up the dependencies in our module properties screen. You can right click HelloYou and go in Properties. Another way to do the same is going in File → “HelloYou” Properties.
Figure 12. File → “HelloYou” Properties.
In the Project Properties screen select Libraries in the left side, Categories. There are listed the Java, Netbeans and all Module Dependencies of your module. By default you’ll see Utilities API module dependence.
Figure 13. Module Dependences.
Click in the button Add (that one near the module dependencies). You’ll see the Add Module Dependency screen where are listed all Netbeans modules.
Figure 14. Add Modules Dependency
We want add an dependency for the Dialogs API. Type “dialogs” in the filter text field.
Figure 15. Dialogs API.
Select the module Dialogs API and click OK. Now our module have two dependencies: Utilities API and Dialogs API.
Figure 16. Dialogs API and Utilities API.
Now for the first time, let’s right some code.
In HelloAction.java file there’s a class HelloAction that extends CallableSystemAction (an abstract class). In the method performAction() there’s nothing but:
//TODO implement action body
We will rewrite the performAction method:
public void performAction() {
String msg = "Hello Netbeans World!";
int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);
DialogDisplayer.getDefault().notify(d);
}
You will see some warnings (cannot find symbol). Just fix the imports (Ctrl+Shift+I). To test your module, do it again: HelloYou → Install/Reload in Target Platform. A new instance of Netbeans will open and you’ll see our smile face button again. When you click it, Netbeans will show an dialog.
Figure 17. Hello Netbeans World.
Let’s do more. Let’s talk with the user using NotifyDescriptor.InputLine. Will create an input line dialog, get the user name (if he clicks in Ok) and display a message to him.
public void performAction() {
NotifyDescriptor.InputLine question;
question = new NotifyDescriptor.InputLine("Name:",
"What's your name?",
NotifyDescriptor.OK_CANCEL_OPTION,
NotifyDescriptor.QUESTION_MESSAGE);
if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
String msg = "Hello "+question.getInputText()+"!";
int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);
DialogDisplayer.getDefault().notify(d);
}
}
Again, HelloYou → Install/Reload in Target Platform.
After the new Netbeans instance opens, click in our smile face.
That’s it. You made your Netbeans plugin!
Learn more about Netbeans Module Development:
- Introduction to NetBeans Module Development Tutorial – A tutorial I based to make this one.
- NetBeans Modules and Rich-Client Applications Learning Trail – All resources you need to learn more about Netbeans Platform. Lot’s of tutorials.
- Netbeans Plugin Portal – You can download and also make a NBM file to share your plugins with the community.
- Rich Client Programming: Plugging into the NetBeans Platform – Tim Boudreau, Jaroslav Tulach and Geertjan Wielenga wrote the best book about Netbeans platform. I’m reading it.
- Netbeans Developer FAQ – An big FAQ for person writing NetBeans extension modules (plug-ins), or applications based on the NetBeans platform.
added in 02.27.08: now this tutorial is also available in the Netbeans Wiki.
This is interesting, well, in my first tech talk I show how to create a module using swing and NetBeans platform. But now I’m going to use this to.
Great Job you are doing.
Saludos
rik
Very easy to follow. Cool!
Good article, It looks that making netbeans plugin become easier after some years 🙂
May I ask which Operating system you were in when you made the screenshots? GUI looks very nice and soft.
Thanks
legolas, I was using Netbeans 6.0 in Ubuntu 7.10 with some Compiz effects.
Nice Walkthrough on how to create a Netbeans plugin!
I think I’m gonna try it one of these days.
Thanks for that great material and keep going with that good work! 🙂
Wow, this is the program James Gosling thinks makes Emacs obsolete? In Emacs, this whole tutorial can be summed up as:
1. Add the following text to your .emacs file:
(defun hello-you (name) (interactive “MWhat’s your name? “)
(message “Hello %s!” name))
2. Run your plugin with “M-x hello-you”. Or bind it to your shortcut key of choice. Or a toolbar button, if you’re really allergic to typing.
Man, I’m so glad we’ve got away from that 1970s junk. All these dialog boxes are so much more productive.
Hi Silveira Neto,
Thanks for this nice article.
suresh
Hi,
Great news on the Performance Enhancements in NB6.1.
What happened to the DocBook plugin for NetBeans ? I really would like it at the moment !
Regards,
Edward.
Great Work…
Great work!
althi just wanted to ask…
wt do i do if i wanted a link to my proj wth this icon tat we created?..how to go bout if i want to write any code,,like for creating a DB conn,,or adding stuff to the pallet
@rks If I understood you are looking for, I recommend to you these documents:
Platform Development Learning Trail
Platform API Documentation and Tutorials
Platform Developer FAQ.
Wiki.netbeans.org
In those places you can find good articles and tutorials about Netbeans platform and how to make good modules.
it’s very easy, but greate job Pel
Interesting…
I am testing in this moments…
Great!! Thanks Silveira great tutorial,
nicely done and easy to understand.
I think ill try my hand at creating one soon..
Thanks
Do you guys have a recommendation section, i’d like to suggest some stuff
Great quality stuff.
Great ! Thanks!
muito obrigado!! thanks a lot!! finally i know how to start.
Silveira hello I read your article, but I have some doubts about the dependencies between various modules that are being developed, I have a module that requires from another module classes I am creating, I have some errors when I compile Due to this.
How can i resolve this dependency problem
Silveira hello I read your article, but I have some doubts about the dependencies between various modules that are being developed, I have a module that requires from another module classes I am creating, I have some errors when I compile Due to this.
How can i resolve this dependency problem
thanks a lot!!!
It was quite useful for me, I didn’t know anything about modules and now I’m familiar with them.
Thanks Silveira.
but I still have some problems with dependencies between modules.
I have 3 modules which module A depends on B, and module B depends on C.
but I don’t know how to tell netbeans this dependency chain…
Hi Mahtab, I guess you can set the dependency in your project module properties itself. You point to the other module project.
Hi, great tutorial. I have a question, how can I create a JFrame and make it visible blocking the IDE?