Home > Articles > Programming > Java

This chapter is from the book

This chapter is from the book

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."

  • + Share This
  • 🔖 Save To Your Account