Use of JTree (summary, Very concise)

Source: Internet
Author: User

Using the JTree component

Some concepts:

    1. Root node: top-most point
    2. Child nodes: nodes below the root node
    3. Leaf node: When a node does not have any child nodes
    4. Branch nodes: Conversely called
Construct JTree with Hashtable to TreeNode structure JTree

Each node on the JTree represents a TreeNode object. TreeNode itself is a interface.

TreeNode Inheriting Mutabletreenode implementation Defaultmutabletreenode

Construct JTree with TreeModel

The tree can be built with the data model, and the datamodel of the tree is called TreeModel, and the benefit of this pattern is that it can trigger a tree-related event and deal with some of the changes that the book may produce.

We can inherit Deafulttreemodel constructs JTree

Change the appearance of JTree

Replace the JTree node pattern jtree work with the Treecellrenderer interface to run the drawing node, but Java provides a well-implemented class for us to use, Defaulttreecellrenderer.jtree event-handling format

Two commonly used event handling for JTree: 1. treemodeevent and 2. treeselectionevent

treemodeevent

When there is any change in the structure of the tree, the Treemodeevent event is generated and the Treemodellistener interface must be implemented to handle such an event.

treeselectionevent

Use of JTree (summary, Very concise)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.