A PropertyTree is a means to organize a set of properties of whatever kind
they might 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.1
Version 3.1 was released on friday, july 27th. 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);
// If you want to use it in a list instead, here's how: DefaultListModel model = new DefaultListModel(); 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:
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 above (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.
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.