遍历所有节点 : 树 « Swing « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » Swing »  
14. 66. 14. 遍历所有节点
  1. preOrderEnumeration(): The first node is the node itself. The next node is that node's first child, then it's the first child of that first child. Once a leaf node with no children is found, the next child of its parent is put in the Enumeration and its children are added to the list accordingly until no nodes are left.
  2. depthFirstEnumeration() and postOrderEnumeration(): Return an Enumeration that has practically the opposite behavior of preOrderEnumeration(). Instead of including the current node first and then adding the children, these methods add the children first and then add the current node to the Enumeration.
  3. breadthFirstEnumeration(): Returns an Enumeration of nodes added by level.
遍历所有节点
import java.awt.BorderLayout;
import java.util.Enumeration;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

public class PostPreorderAndDepthEnumeration {
  public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode mercury = new DefaultMutableTreeNode("Mercury");
    root.add(mercury);
    DefaultMutableTreeNode venus = new DefaultMutableTreeNode("Venus");
    root.add(venus);
    DefaultMutableTreeNode mars = new DefaultMutableTreeNode("Mars");
    root.add(mars);
    JTree tree = new JTree(root);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300150);
    frame.setVisible(true);

    Enumeration e = root.preorderEnumeration();
    while(e.hasMoreElements()){
      System.out.println(e.nextElement());
    }
    
    e = root.postorderEnumeration();
    while(e.hasMoreElements()){
      System.out.println(e.nextElement());
    }
    
    e = root.depthFirstEnumeration();
    while(e.hasMoreElements()){
      System.out.println(e.nextElement());
    }
  }

}
14. 66. 树
14. 66. 1. 创建JTree
14. 66. 2. 用向量来存储JTree值用向量来存储JTree值
14. 66. 3. 从向量创建JTree
14. 66. 4. 节点树节点树
14. 66. 5. Scrolling Trees: public void scrollPathToVisible(TreePath path) and public void scrollRowToVisible(int row)Scrolling Trees: public void scrollPathToVisible(TreePath path) and public void scrollRowToVisible(int row)
14. 66. 6. 遍历树遍历树
14. 66. 7. JTree.lineStyle属性JTree.lineStyle属性
14. 66. 8. Changing the icons of a tree: UIManager.put(Tree.openIcon, new ImageIcon(yourFile.gif));Changing the icons of a tree: UIManager.put(Tree.openIcon, new ImageIcon(yourFile.gif));
14. 66. 9. 水平之间的界线一级节点水平之间的界线一级节点
14. 66. 10. Using Boolean value cell renderer to display boolean and non-boolean valuesUsing Boolean value cell renderer to display boolean and non-boolean values
14. 66. 11. Creating DefaultTreeCellEditor from its Default Tree RendererCreating DefaultTreeCellEditor from its Default Tree Renderer
14. 66. 12. 增加DefaultMutableTreeNode增加DefaultMutableTreeNode
14. 66. 13. JTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION)
14. 66. 14. 遍历所有节点遍历所有节点
14. 66. 15. JTree.DynamicUtilTreeNode类JTree.DynamicUtilTreeNode类
14. 66. 16. 树将扩张监听树将扩张监听
14. 66. 17. 了解树节扩展和收缩了解树节扩展和收缩
14. 66. 18. 动态树
14. 66. 19. 单独计算每一行行高
14. 66. 20. 设置行高JTree
14. 66. 21. 所有行15像素高度
14. 66. 22. Preventing Expansion or Collapse of a Node in a JTree: override JTree.setExpandedState()
14. 66. 23. Listening for Expansion and Collapse Events in a JTree Component
14. 66. 24. Expansion and Collapse Events in a JTree are fired before a node is expanded or collapsed can be vetoed, thereby preventing the operation.
14. 66. 25. 创建JTree组件
14. 66. 26. 访问所有节点的JTree组件
14. 66. 27. 遍历所有树节点
14. 66. 28. 在JTree组件找到一个节点
14. 66. 29. Search backward from last visible row looking for any visible node whose name starts with prefix.
14. 66. 30. Find the path regardless of visibility that matches the specified sequence of names
14. 66. 31. Preventing the Expansion or Collapse of a Node in a JTree Component
14. 66. 32. 弹出菜单JTree
14. 66. 33. 添加编辑节点JTree
14. 66. 34. 拖放的一组文件到树
14. 66. 35. JTree外观
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.