What API do I want to use for x, y or z?
Note: These pages are being reviewed.
- I want to …
- Show my component in the main window
- Write to the output window
- Show a Tree, List or other control with a list of some objects
- Provide an Editor for a particular kind of file
- Add a menu item to the main menu
- Show content in the Navigator window when a file of a certain type is selected
- Show a progress bar
- Set the main window’s statusbar text
- Allow other modules to register objects and then find those objects dynamically at runtime
- Save some settings persistently
- Run some code at application startup/shutdown
- Add a Panel to the Options dialog
- Find/listen to/manipulate the set of open projects
- Create a graph editor such as the Mobility Pack uses
Here is a list of common things people need to do, and a very short description of how you do them. From here, use the Javadoc and tutorials to get more information.
Use the I/O API. Call
IOProvider.getDefault().getInputOutput("Something"). The object returned has getters for standard output, standard error and input streams which write to and read from a tab in the output window.
Use the Nodes API to create a hierarchy of Node objects, each representing one object in your data model. Then use the Explorer API to show the Nodes - it contains tree, list, table, combo box and other controls which can show a hierarchy of Nodes. Nodes are very easy to add popup menus to, decorate with icons and html-ized display names, etc. and are a lot less work than using Swing components directly. See also the Nodes API Tutorial.
No specific NetBeans APIs are needed - you can just create a subclass of Swing’s
AbstractAction, and register it in your modules layer.xml file. Or, use the new Action template in the IDE to generate a subclass of
SystemAction for you and all the registration code, and fill in the action-performing logic.
Use the Navigator API to create a navigator panel provider; you then somehow parse the file and can create any component you want to show in the Navigator, and populate it with whatever you want.
Use the Progress API - call
ProgressHandleFactory to create a
ProgressHandle for you. That is an object with methods for setting the progress, status text, number of steps, etc. and is fairly self-explanatory. Remember to make sure the code showing progress is not running in the AWT Event thread.
Use the UI Utilities API. Simply call
Define a folder in the System Filesystem in the XML layer file of your module. Other modules can register instances of whatever class you specify by declaring
.instance files in their own XML layer files. You can find them at runtime using
Lookups.forPath("path/to/my/folder") to get an instance of Lookup that you can query for these objects.