Overview of NetBeans Java API Samples in Plugin Portal
Hint Template. Want to create new hints in the Java editor? By "hint" I mean those small error-like messages that appear when you do something dubious in your code. This template gives you a great start. You can specify a category and a prefix for your Hint class. Then the Hint class is generated, creating a stub for your own hint. By default, whenever the user types "JOptionPane.showMessageDialog", a hint will appear. The necessary dependencies and layer.xml entries are automatically generated by the template.
Extended Java Project Sample. How do you create a wizard for creating new project source structures? This sample shows you how. Based on the IDE's Anagram Game, the sample provides a new panel which causes a Java class to be generated, filled with entries typed in the panel. This is a very typical scenario, something you would always need to do when creating your own wizards, whether for projects or files. Therefore, this sample is a great starting point, also because it shows how FreeMarker can be leveraged in this context.
HTML Editor Sample. Want to see a simple application on top of the NetBeans Platform? Here's a nice small example. For no coding whatsoever, i.e., there isn't a single Java class in this application, a complete HTML editor can be created on top of the NetBeans Platform. How? By selecting the modules you need from the NetBeans Platform and NetBeans IDE and by excluding those that you don't need. And by tweaking some XML files to customize the layout. Everything is provided by this sample. To recreate this sample from scratch in NetBeans IDE 6.1 Beta, see NetBeans Platform 6.1 Quick Start Tutorial.
HTML Hyperlink Provider Sample. In Java classes in NetBeans IDE, when you hold down the Ctrl key and move the mouse over an identifier, the identifier becomes a clickable hyperlink which, when clicked, causes the cursor to jump to the related identifier's definition. This sample shows how to create a hyperlink of this kind in HTML files. Here the AHREF tag's value becomes hyperlinked. Once clicked, the referenced HTML file opens in the editor.
Java Source File Palette Sample. In NetBeans IDE, palettes are provided containing items that can be dragged and dropped into an editor. On the drop, a snippet of code is generated at the drop location. How do you create such a palette? Do you need to add the code for the palette to the same module where the related editor is created? No. Since 6.0, you can create a palette in one module, register it for a particular MIME type, and then, when that MIME type's editor opens, your palette will open too. How to do this is demonstrated in this sample.
Marilyn TreeTableView Sample. The NetBeans TreeTableView is notoriously difficult to understand. Better to learn how to work with it outside the NetBeans Platform, which is what this sample lets you do. It provides a standalone Java SE application. Very small, it provides just the minimal set of classes needed for creating a TreeTableView. Here the data consists of information about films starring Marilyn Monroe.
Master Detail Nodes Example. Sample Master/Detail view using the Nodes API, by Tim Boudreau. Once you install the module, look under the Window menu, open the master/detail explorer, then inspect the sources to learn how the view was created.
NetBeans Tip of the Day Sample. How do you integrate a "Tip of the Day" feature into your NetBeans Platform application? This example uses SwingLabs JXTipOfTheDay functionality and makes use of the 6.0 NbPreferences API class. You also learn how to read a template from a module and write it to a folder in the NetBeans user directory, although the FreeMarker approach in example 2 above should probably now be the preferred approach.
Selection Suite Sample. The end result of the 4-part selection tutorial by Tim Boudreau. This module installs the sample in the New Project wizard, within the NetBeans Plug-in Modules samples category. For details, go here. The sample illustrates how Lookup, Nodes, and Property Editors are used and created.
Simpsons Sample. Example demonstrating use of Visual Library API. The sample installs a "scene" which can be opened from the Window menu. The sample provides Simpsons characters as widgets, which can be dragged and dropped from the palette onto the "scene", moved around, and connected to each other. Backgrounds can be changed too, demonstrating how LayerWidgets are used.
Visual Library API Sample. The simplest scenario for Visual Library API implementations. This is the equivalent of a "Hello World" scenario for the Visual Library API in the context of the NetBeans Platform. Drag and drop shapes from the palette onto a "scene" in a JScrollPane on a TopComponent.
Which Element Sample. Simple module by Sandip Chitale, based on new (Javac based) Java language infrastructure. It shows info about the Element under the caret in a read-only text field (40 column) in the status bar.
Text File Dictionary Project Template. Illustrates how to provide code completion for a NetBeans editor. In this case, the sample provides code completion in text files. The words in the code completion box come from a text file registered in the Options window. You could register a file with ANY content (i.e., any language or word choices) there. Then that will be used. The definitions in the documentation section come from a web service, which provides definitions for English words only.
Though I cannot guarantee that each of the samples above will work out of the box in 6.0 or 6.1, since some of them were written for earlier versions without having been upgraded yet, I am pretty sure that in most cases only a few tweaks would be needed to align them with the latest versions of NetBeans IDE. Any comments or problems with these samples? Feel free to leave them here in the comments to this article.