JTree Example Java Swing

JTree Example Java Swing

JTree is a swing component that can be used to display a hierarchy of data like Window Explorer. Each element in the tree becomes a node. For a node another node can be added thus constructing a tree. Nodes are expandable and collapsible. Collapsible nature hides some nodes, thus the user is not shown the unnecessary data he is not meant for.

DefaultMutableTreeNode class is used to create a node.

TreePath getPathForLocation(int x, int y) returns the path of the node clicked.

Example on JTree

Following is the HTML code to run the above JApplet:


Leave a Reply

Your email address will not be published. Required fields are marked *