NetBeans Platform: Combobox in property editor

Happy new year everyone !

I'm going to talk today about something simple GUI-wise but quite a lot asked on the mailing lists: how does one display a combobox in the property editor ? Actually, how does one use an editor that displays a combobox.

What should get you started with this task (and other editor customizing) is a little file from the Platform javadoc.

This is what we plan to get:

In order to do this note the Custom parameters in core editors paragraph from the above link and the fact that for java.lang.Integer properties there are some custom keys we can use:
  • stringKeys - an array of strings to be present in the combobox
  • intValues - an array of integers representing the values of the selection in the combobox.
So something like this:

Node.Property p=new YourProperty(Integer.class);
p.setValue("intValues",new int[]{1,2,3,4});
p.setValue("stringKeys",new String[]{"One","Two","Three","Four"});

is all you need.

Note: Please take care that for the current property
  • #getValue is the index in the intValues array. So if you want to see "Three" in the combobox, you return the number 2 in #getValue.
  • #setValue is called with the actual number from intValues (not the index). So if the user selects "Four" from the combobox, #setValue(4) will be called.