Note: These pages are being reviewed.
- What API do I use for …
- 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
- Apache Migration Information
What API do I use for …
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.
I want to …
Show my component in the main window
Write to the output window
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.
Show a Tree, List or other control with a list of some objects
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.
Provide an Editor for a particular kind of file
Add a menu item to the main menu
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.
Show content in the Navigator window when a file of a certain type is selected
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.
Show a progress bar
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.
Set the main window’s statusbar text
Use the UI Utilities API. Simply call
Allow other modules to register objects and then find those objects dynamically at runtime
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.
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
Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DefFaqMapApisToTasks , that was last modified by NetBeans user Skygo on 2013-12-13T23:52:13Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.