O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tree Events

Trees generate three new types of events that are worth mentioning. Apart from the obvious selection and expansion events from the graphical side, you can also catch structural changes with model events.

The TreeModelEvent Class

The TreeModelEvent class encapsulates model changes in the form of the path that has changed, as well as information on the children of that path.

Fields

protected int[] childIndices, protected Object[] children

Hold the children and their indices in the parent node associated with this event.

protected TreePath path

Holds the path to the parent of the children associated with this event.

Constructors

public TreeModelEvent(Object source, Object path[], int childIndices[], Object children[]), public TreeModelEvent(Object source, TreePath path, int childIndices[], Object children[])

These constructors allow you to build an event that encompasses the children of a modified node. This type of event is useful if the references to the node’s children have changed, or if the number of children has changed.

public TreeModelEvent(Object source, Object path[]), public TreeModelEvent(Object source TreePath path)

If the modified node is the only interesting node for this event (if its value changed, but nothing happened to its children, for example) then you can use these constructors.

Methods

public int[] getChildIndices(), public Object[] getChildren()

If the event contains information about the affected children of a node, you can retrieve those indices and the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required