Example usage for javax.swing.tree MutableTreeNode setParent

List of usage examples for javax.swing.tree MutableTreeNode setParent

Introduction

In this page you can find the example usage for javax.swing.tree MutableTreeNode setParent.

Prototype

void setParent(MutableTreeNode newParent);

Source Link

Document

Sets the parent of the receiver to newParent.

Usage

From source file:com.lh.leap.ui.LocationNodeImpl.java

public void insert(MutableTreeNode mutableTreeNode, int i) {
    mutableTreeNode.setParent(this);
    children.add(i, (LocationNodeImpl) mutableTreeNode);
}

From source file:plugin.notes.gui.NotesTreeNode.java

/**
 * Inserts a new MutableTreeNode into this node as a child.
 *
 * @param child/*  w ww .  j a v  a 2  s  . c om*/
 *          Child to insert
 * @param index
 *          Location to insert it.
 */
@Override
public void insert(MutableTreeNode child, int index) {
    if (!allowsChildren) {
        throw new IllegalStateException("node does not allow children");
    } else if (child == null) {
        throw new IllegalArgumentException("new child is null");
    } else if (isNodeAncestor(child)) {
        throw new IllegalArgumentException("new child is an ancestor");
    }

    if (!hasBeenPopulated) {
        populate();
    }

    MutableTreeNode oldParent = (MutableTreeNode) child.getParent();

    if (oldParent != null) {
        oldParent.remove(child);
    }

    child.setParent(this);

    if (children == null) {
        children = new Vector<>();
    }

    children.insertElementAt(child, index);
}

From source file:plugin.notes.gui.NotesTreeNode.java

/**
 * removes the child node at index/*from   ww  w .  j a  v a  2s.c o m*/
 *
 * @param index
 *          index of child to remove
 */
@Override
public void remove(int index) {
    if (!hasBeenPopulated) {
        populate();
    }

    MutableTreeNode child = (MutableTreeNode) getChildAt(index);
    children.removeElementAt(index);
    child.setParent(null);
}