Using the JTree component
Some concepts:
- Root node: top-most point
- Child nodes: nodes below the root node
- Leaf node: When a node does not have any child nodes
- Branch nodes: Conversely called
Construct JTree with Hashtable to TreeNode structure JTree
Each node on the JTree represents a TreeNode object. TreeNode itself is a interface.
TreeNode Inheriting Mutabletreenode implementation Defaultmutabletreenode
Construct JTree with TreeModel
The tree can be built with the data model, and the datamodel of the tree is called TreeModel, and the benefit of this pattern is that it can trigger a tree-related event and deal with some of the changes that the book may produce.
We can inherit Deafulttreemodel constructs JTree
Change the appearance of JTree
Replace the JTree node pattern jtree work with the Treecellrenderer interface to run the drawing node, but Java provides a well-implemented class for us to use, Defaulttreecellrenderer.jtree event-handling format
Two commonly used event handling for JTree: 1. treemodeevent and 2. treeselectionevent
treemodeevent
When there is any change in the structure of the tree, the Treemodeevent event is generated and the Treemodellistener interface must be implemented to handle such an event.
treeselectionevent
Use of JTree (summary, Very concise)