- The Tree Control
- Tree Appearance
- The TreeNode Interface
- The MutableTreeNode Interface
- The DefaultMutableTreeNode Class
- The TreePath Class
- What is a Leaf?
- Tree Expansion and Traversal
- Expanding and Collapsing Nodes under Program Control
- Tree Expansion Events
- Making Nodes Visible
- Controlling Node Expansion and Collapse
- Tree Model Events
- Implementation Plan for the File System Control
- File System Tree Control Implementation
- Using the File System Tree Control
- Custom Tree Rendering and Editing
- Customizing the Default Tree Cell Renderer
- ToolTips and Renderers
- Custom Cell Editors
- Controlling Which Nodes Can Be Edited
- Controlling Editability by Subclassing JTree
- Programmatic Control of Editors
- Editing Trees with Custom User Objects
- The valueForPathChanged Method
- The Tree Implementation
- The Cell Editor
- The Cell Renderer
This chapter introduced the Swing tree control, one of two powerful data display components that you have at your disposal. After seeing the basic components of a tree, you learned how trees are created and how the user can manipulate them by expanding and collapsing nodes and making selections. You also saw how these actions are reflected in the tree itself and how they can be intercepted by applications and by custom components derived from the JTree class.
One of the more popular uses for a tree control is to display the content of a file system. A large portion of this chapter was devoted to creating a subclass of JTree that can show a file system in hierarchical form. The implementation of this control reveals much of the inner workings of the tree's data structures.
Finally, you saw several ways in which the tree's appearance can be customized to suit the needs of particular applications and discovered how to allow the user to edit the contents of a tree, while still making sure that only meaningful changes can be made.