Geertjan's Blog

  • December 21, 2010


Geertjan Wielenga
Product Manager
Let's use the org.openide.explorer.propertysheet.PropertyPanel component, a generic GUI component for displaying and editing a JavaBeans property:

The window in the lower left above uses the PropertyPanel, in fact all 3 components you see there are PropertyPanels. (So does the Properties window that you see above, but that's a predefined component that uses the PropertyPanel, while in this blog we want to create a custom component that uses PropertyPanel too.) The PropertyPanel is automatically synchronized with the other two windows you see above.

Start by creating a domain object, e.g., "Car", with properties "type" and "year". Make sure to provide PropertyChangeSupport, with firing of property changes in the setters.

Define your Node as follows:

public class CarNode extends BeanNode implements PropertyChangeListener {
public CarNode(Car bean) throws IntrospectionException {
super(bean, Children.LEAF, Lookups.singleton(bean));
public String getDisplayName() {
Car c = getLookup().lookup(Car.class);
if (null != c.getType()) {
return c.getType();
return super.getDisplayName();
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("type")){
String oldDisplayName = evt.getOldValue().toString();
String newDisplayName = evt.getNewValue().toString();
fireDisplayNameChange(oldDisplayName, newDisplayName);

Display the Node above in a BeanTreeView within a TopComponent in the "explorer" mode of the application. Notice that it listens for property changes on the "type" property and then fires a change of the display name.

In the TopComponent on the lower left above, i.e., the one containing the PropertyPanels, set a LookupListener that is sensitive to BeanNodes and then implement the methods below:

private GridBagConstraints gbc = new GridBagConstraints();
private Lookup.Result<BeanNode> result = null;
public void resultChanged(LookupEvent le) {
Collection<? extends BeanNode> nodes = result.allInstances();
if (!nodes.isEmpty()) {
for (Node node : nodes) {
PropertySet[] sets = node.getPropertySets();
for (PropertySet propertySet : sets) {
Property[] props = propertySet.getProperties();
for (Property property : props) {
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.BOTH;
property.setValue("suppressCustomEditor", true);
PropertyPanel cpp = new PropertyPanel(property);
add(cpp, gbc);
public void componentOpened() {
result = Utilities.actionsGlobalContext().lookupResult(BeanNode.class);
resultChanged(new LookupEvent(result));
public void componentClosed() {

That's all. Now you have created a PropertyPanel for each property retrieved from the current BeanNode.

Join the discussion

Comments ( 1 )
  • guest Tuesday, November 26, 2013

    how to add a pop-up menu in the property sheet? Thanks

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.