Package javax.swing.tree

Examples of javax.swing.tree.TreeModel


   * Checks whether the model has been changed, and if so unregister and register listeners.
   */
  private void checkModel()
  {
    // find out whether the model object (the TreeModel) has been changed
    TreeModel model = getModelObject();
    if (model != previousModel)
    {
      if (previousModel != null)
      {
        previousModel.removeTreeModelListener(this);
      }

      previousModel = model;

      if (model != null)
      {
        model.addTreeModelListener(this);
      }
      // model has been changed, redraw whole tree
      invalidateAll();
    }
  }
View Full Code Here


   *            The tree node
   * @return iterable presentation of node children
   */
  public final Iterator<Object> nodeChildren(Object node)
  {
    TreeModel model = getTreeModel();
    int count = model.getChildCount(node);
    List<Object> nodes = new ArrayList<Object>(count);
    for (int i = 0; i < count; ++i)
    {
      nodes.add(model.getChild(node, i));
    }
    return nodes.iterator();
  }
View Full Code Here

   * Checks whether the model has been changed, and if so unregister and register listeners.
   */
  private final void checkModel()
  {
    // find out whether the model object (the TreeModel) has been changed
    TreeModel model = (TreeModel)getModelObject();
    if (model != previousModel)
    {
      if (previousModel != null)
      {
        previousModel.removeTreeModelListener(this);
      }

      previousModel = model;

      if (model != null)
      {
        model.addTreeModelListener(this);
      }
      // model has been changed, redraw whole tree
      invalidateAll();
    }
  }
View Full Code Here

            getTree().updateTree(target);
        }
    }

    private void setTreeView() {
        final TreeModel treeModel = createTreeModel();
        keyTree.setModelObject(treeModel);
    }
View Full Code Here

        final TreeModel treeModel = createTreeModel();
        keyTree.setModelObject(treeModel);
    }

    private void setFlatView() {
        final TreeModel flatModel = creatFlatModel();
        keyTree.setModelObject(flatModel);
    }
View Full Code Here

            NodeBean node = new NodeBean(key, key);
            DefaultMutableTreeNode child = new DefaultMutableTreeNode(node);
            rootNode.add(child);
        }

        TreeModel treeModel = new DefaultTreeModel(rootNode);
        return treeModel;
    }
View Full Code Here

        HashMap<String, DefaultMutableTreeNode> hashMap = new HashMap<String, DefaultMutableTreeNode>();
        for (String key : keySet) {
            addNodes(rootNode, key, hashMap);
        }

        TreeModel treeModel = new DefaultTreeModel(rootNode);
        return treeModel;
    }
View Full Code Here

        Rectangle           cellRect = tree.getPathBounds(treePath);
        return cellRect;
    }

    public Component getRendererComponent() {
        TreeModel treeModel = tree.getModel();
        TreePath treePath = tree.getPathForRow(rowIndex);
        TreeCellRenderer renderer = tree.getCellRenderer();
        boolean isSelected = tree.isPathSelected(treePath);
        boolean isExpanded = tree.isExpanded(treePath);
        boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow();
        Object item = treePath.getLastPathComponent();
        boolean isLeaf = treeModel.isLeaf(item);
        Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus);
        component.setFont(tree.getFont());
        return component;
    }
View Full Code Here

    public TreeModel getModel() {
        return treeModel;
    }

    public void setModel(final TreeModel model) {
        TreeModel oldValue = treeModel;
        if (treeModel != null) {
            treeModel.removeTreeModelListener(treeModelListener);
        }
        clearToggledPaths();
        if (getSelectionModel() != null) {
View Full Code Here

    }

    // If expand is true, expands all nodes in the tree.
    // Otherwise, collapses all nodes in the tree.
    public static void expandLevels(JTree tree, int levels, boolean expand) {
        TreeModel model = tree.getModel();
        if (model == null) {
            return;
        }
        TreeNode root = (TreeNode)model.getRoot();
        // Traverse tree from root
        expandLevels(tree, new TreePath(root), levels, expand);
    }
View Full Code Here

TOP

Related Classes of javax.swing.tree.TreeModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.