Another aspect of the JTree is the add(Component) method, which comes from being a subclass of the Container class.
(If you think of a traditional organizational chart as a tree, then an example of a path would be the line drawn from you to the president or CEO.) Leaf: A special kind of node.As its name implies, this is the node at the end of a path.So how do you represent your current business objects in a JTree without altering your class definition of the business objects? In both examples the objectives are to minimize (1) the coupling between the business objects and the JTree, and (2) the amount of effort and code to accomplish the tasks.In both examples I use a class called Vehicle that represents any business object and that can be displayed in hierarchical fashion.For example, one instance of the Vehicle class might be called "Motor Vehicle." The class could contain subtypes of Car, Truck and Van.
These vehicles, while separate, share the commonality of being a motor vehicle.In the first example - Add Data_Example (see Listing 1) - associating a business object's data to the JTree is done using the default helper classes: javax. These methods allow the addition and removal of nodes from the JTree.Since my business object, the Vehicle class, doesn't implement the Mutable Tree Node interface, it can't be directly added to the JTree.(In the examples provided, the Vehicle class is used to represent the business object.) Editor: This is a component (usually an extension of a JComponent) that has the unique role of allowing the user to change the data of a specific node.Renderer: This is a component (usually an extension of a JComponent) that has the unique role of deciding how a node's data is to be displayed within the context of the JTree when a user isn't editing the data.(Note: As of JDK 1.2/Swing 1.1, a node can have only one parent.) User Object: Refers to the business object associated with a node.