Page 2 of 5
All Swing data-representation components are implemented with this design pattern in mind, so all Swing applications will inherently benefit from this immense design flexibility.
JTree component architecture
The following figure illustrates the Model and UI (View-Controller) portions of the JTree component.

Swing's JTree component architecture
JTree, the portion that manages the rendering of the tree data, is defined by the TreeUI interface.TreeModel object. As you'll see later, the data can be any arbitrary hierarchy of information; it need not even all be held in memory
at once, it can be simply fetched as needed.TreeSelectionModel; this allows Swing to manage different selection strategies (continuous selection, discontinuous selection, for example)
We'll now take a more detailed look at the classes that are involved in Swing's tree component:
Most of JTree's model entities are part of the com.sun.java.swing.tree package. Below is a simple class diagram that describes the main
entities and the relationships between them. (Note that there are more classes in the package, but I omitted those that aren't
directly related to the model part of JTree.)

Main entities of the Swing tree package
In keeping with good design practice, the tree package is divided into abstraction and implementation layers. In fact, the tree package provides several degrees of abstraction. At the highest level are the TreeModel, TreeSelectionModel, and TreePath interfaces and classes, which simply describe a data/selection model of Objects. Practical implementations of these interfaces are provided by DefaultTreeModel and DefaultTreeSelectionModel, which describe a tree consisting of TreeNode and MutableTreeNode objects. Finally, a practical implementation of these node interfaces is provided by DefaultMutableTreeNode. These different levels of abstraction are described in detail below.
Interfaces denote the contract that a given component must fulfill in order to participate in a particular collaboration. The tree package defines one main
data model contract -- the TreeModel interface, and two node interfaces, TreeNode and MutableTreeNode -- that you use when working with the default tree model implementation. Data-related communications are performed with TreeModelEvent and TreeModelListener.
Let's examine these contracts (interfaces) in more detail.
The TreeModel contract
The TreeModel interface defines the contract that a general tree-like hierarchical collection for a hierarchical data must fulfill. The
interface should be implemented by any class that holds hierarchical data (the File system, for example) and wishes to use
the JTree component as its GUI. In order to keep the contract as general as possible, all of the TreeModel methods accept and return an Object class, instead of a more constrained type, which allows you to implement the interface for constructing your own hierarchical
data structures of arbitrary datatypes.