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:

Find Type 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.

Comments:

Post a Comment:
Comments are closed for this entry.
About

sandipchitale

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today