Tip: api to show Java type chooser dialog in NetBeans 6.0
While implementing the Add Property module, Jan Lahoda pointed out an api available in NetBeans 6.0 Java support which can show a Java Type chooser dialog. Here is the snippet of code to show the dialog:
FileObject fileObject = ...; // Some java file's file object in a NetBeans Project.
ElementHandle<TypeElement> type = TypeElementFinder.find(ClasspathInfo.create(fileObject), null);
if (type != null) {
// use the type somehow
}
which shows the dialog:

You can use this api in your module any time you want to select a Java type. You will have to add the following dependencies to your module:
- Java Source
- Java Source UI
- Java Support APIs
- Javac API Wrapper
The TypeElementFinder api is implemented in Java Source UI module. You can further customize the dialog by passing the second argument to the find() method.
For some reason this does not appear in the NetBeans 6.0 API docs - probably because this is not an official API yet.
Posted by sandipchitale
( Nov 23 2007, 09:36:49 PM PST ) Permalink