NetBeans Property Editors for and String Arrays

I drag and drop a few PropertyPanels (which you can get into your palette by right-clicking inside it, choosing 'Palette Manager', then 'Add from JAR', and then browsing to 'platform/modules/org-openide-explorer.jar' in the NetBeans IDE installation directory) onto a TopComponent...

I then run the application and when I switch from one node to another, the property panels automatically update themselves, in the same way as the Properties Window:

The small "..." buttons to the right of each of the property panels are created automatically. The first two, above, are not so interesting, because the property in both cases is of type String. However, the property of the third property panel is For that reason, when you click on the small button... a file chooser opens! And, since the type of the property bound to the fourth property panel is a String Array, this is what you see when you click on the last button above:

I.e., the NetBeans Platform has a predefined property editor for and for String[].

Try it yourself. Create a Person object with this content:

public class Person {

    String name;
    String city;
    File photo;
    String[] courses;

    public Person(String name, String city, File file, String[] courses) { = name; = city; = file; = courses;

    public String[] getCourses() {return courses;}
    public void setCourses(String[] courses) { = courses;}
    public File getPhoto() {return photo;}
    public void setPhoto(File photo) { = photo;}
    public String getCity() {return city;}
    public void setCity(String city) { = city;}
    public String getName() {return name;}
    public void setName(String name) { = name;}

Now create a node hierarchy, using BeanNode, and display the node hierarchy in a BeanTreeView, with multiple tutorials that can help you on the NetBeans Platform Learning Trail. Finally, create a TopComponent like the one shown in the first screenshot above, then use a LookupListener to listen for Node classes, and do the following with Nodes:

public void resultChanged(LookupEvent ev) {
    if (personResult.allInstances().iterator().hasNext()) {
        Node personNode = personResult.allInstances().iterator().next();
        Property<?>[] properties = personNode.getPropertySets()[0].getProperties();
        for (Property prop : properties) {
            if (prop.getName().equals("name")) {
                prop.setValue("oneline", Boolean.TRUE);
            } else if (prop.getName().equals("city")) {
            } else if (prop.getName().equals("photo")) {
                prop.setValue("directories", Boolean.FALSE);
            } else if (prop.getName().equals("courses")) {

public void componentOpened() {
    personResult = Utilities.actionsGlobalContext().lookupResult(Node.class);

public void componentClosed() {

Now whenever a new Node is in the Lookup (you could also check whether the Node has a Person in the Lookup, which would make it the Node that you're interested in) the relevant property is bound to a property panel. Depending on what the property is, the NetBeans Platform automatically assigns one of the default property editors, for the properties that it supports.

For further info: Customizing How Properties Are Displayed


Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« May 2016