Skip to main content

Project PropertyTree

Project moved

This project was created back in 2007. In 2014, it moved to Bitbucket. A newer version with more features is available over there. This project site is only still available for legacy reasons. Please head your browser over to the PropertyTree project site on Bitbucket.org to get the newest version.

What is it?

A PropertyTree is a means to organize a set of properties of whatever kind they be.

The default Swing JTree implementation does not allow the use of graphical components like JCheckBoxes. The default JList implementation also uses JLabels, and hasn't even got an «editable» mode to enable users to change the contents of a list. The PropertyTree aimes at solving these problems by using different JPanels instead of one single JLabel to paint the nodes and cells. The result is a nice PropertyTree and a nice PropertyList that take care of your property hierarchy.

If you wonder what a PropertyTree looks like, you'll find a screenshot here or you could test it using the applet at the bottom of this page.

 

Current release: 3.2

Version 3.2 was released on monday, april 9th 2012. Details are found in the changelog. Please do not hesitate to use the issue tracker if you find a bug.

 

Installation and use

A PropertyTree is fairly simple to install and use. Simply have the jar file in your classpath and construct it just like you would construct a JTree:

// first construct a Property object, which will serve as a tree node:
Property     node   = new Property("Cool", true);

// Then use the Property object in the PropertyTree constructor:
PropertyTree myTree = new PropertyTree(node);
// There you go. You now have a PropertyTree already!

// Property objects and DefaultMutableTreeNodes work seamlessly together:
node.add(new DefaultMutableTreeNode("changeable text, but with no callback"));
node.add(new Property("Property object node", "Surveil changes to this text"));

// If you want a list instead, here's how:
DefaultListModel<Property> model = new DefaultListModel<Property>();
model.addElement(node);
PropertyList myList = new PropertyList(model);

That's it! You now already have a PropertyTree or a PropertyList! To benefit from the magic updating, make sure you have a PropertyController object to receive notification as a property is changed. Assuming you create the Property objects from within the PropertyController, you will construct tree nodes like this:

Property parent = new Property("","Names", this);
parent.add(new Property("First name", "John", this));
parent.add(new Property("Family name", "Doe", this));

The this refers to the PropertyController. The tree will notify about changes via the propertyChangeCallback method. Put your handling code in there.

For a complete example, see the source of the applet below (NetBeans construction). There is a main method in the file constructing a JFrame, so you can use the applet as an ordinary application as well.

 

Javadoc documentation

This is where you find the PropertyTree API (javadoc).

You might want to look at the changelog too.

 

Test it

Note that while an ordinary JTree may perfectly well register changes to its nodes, all values will be text values. A PropertyTree, on the other hand, registers all sorts of values!

The differences between a PropertyList and a regular JList are of the same nature, only with the difference that a JList isn't even editable in the first place.

Quick links

 
 
Close
loading
Please Confirm
Close