15.3. JTree
A JTree can display data elements (nodes) in a hierarchical structure. In this section, we illustrate the basic use a of JTree, show how to respond to node selection events, provide an example of a custom tree model (a tree that builds children on the fly), and show how to replace the icons that appear at the tree nodes with custom ones.
Simple JTree
The simplest and most common way to use a JTree is to create objects of type DefaultMutableTreeNode to act as the nodes of the tree. Nodes that have no children are displayed as leaves; nodes that have children are displayed as folders. You can associate any object with a node by supplying a value, known as the “user object,” to the DefaultMutableTreeNode constructor. Node labels are ...
Get Core Web Programming, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.