Java Reference
In-Depth Information
Figure 17-9. You must properly modify the size of a tree renderer.
Creating a Custom Renderer
If the nodes of your JTree consist of information that is too complex to display within the text
of a single JLabel , you can create your own renderer. As an example, consider a tree in which
the nodes describe topics by their title, author, and price, as shown in Figure 17-10. In this case,
the renderer can be a container in which a separate component displays each part.
Figure 17-10. A JTree with a custom renderer
To describe each topic in this example, you need to define a class for storing the necessary
information, as shown in Listing 17-3.
Listing 17-3. Book Class Definition
public class Book {
String title;
String authors;
float price;
public Book(String title, String authors, float price) {
this.title = title;
this.authors = authors;
this.price = price;
}
Search WWH ::




Custom Search