- 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
- Summary
Custom Tree Rendering and Editing
While the general appearance of the tree control is probably sufficient for many applications, it is possible to customize several aspects of the way in which it is rendered using various techniques that will be covered in this section. Some of these techniques work no matter which look-and-feel is installed, while others need to be tailored to work differently with different look-and-feel implementations.
As well as changing a tree's appearance, it is also possible to allow the user to edit the data represented by individual tree nodes. This topic is also covered in this section.
Changing the Appearance of a Tree's Contents
There are two ways in which you can change the appearance of the nodes of a particular tree. The most flexible option is to install your own renderer that implements the TreeCellRenderer interface. If you do this, you have complete control over how each node is displayed. If you just want to change the appearance of the tree slightly, the simplest thing to do is just to customize the basic look-and-feel implementation. The techniques that will be shown here can be used if you want to change the appearance of one particular tree in your application. If you want to make a change that applies to all trees, you may be able to use the simpler technique that will be described in "Changing Properties for All Trees."