Java Code Examples for javax.swing.tree.MutableTreeNode#setParent()

The following examples show how to use javax.swing.tree.MutableTreeNode#setParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebTreeNode.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Removes {@code child} from its present parent (if it has a parent), sets the child's parent to this node,
 * and then adds the child to this node's child {@link List} at index {@code childIndex}.
 * {@code child} must not be {@code null} and must not be an ancestor of this node.
 *
 * @param child child node to insert under this node
 * @param index index in this node's child {@link List} where this node is to be inserted
 * @throws IllegalStateException          if this node does not allow children
 * @throws IllegalArgumentException       if {@code child} is null or is an ancestor of this node
 * @throws ArrayIndexOutOfBoundsException if {@code childIndex} is out of bounds
 * @see #isNodeDescendant(WebTreeNode)
 */
@Override
public void insert ( @NotNull final MutableTreeNode child, final int index )
{
    if ( !allowsChildren )
    {
        throw new IllegalStateException ( "Node does not allow children" );
    }
    if ( isNodeAncestor ( ( N ) child ) )
    {
        throw new IllegalArgumentException ( "New child is an ancestor" );
    }

    final N oldParent = ( N ) child.getParent ();
    if ( oldParent != null )
    {
        oldParent.remove ( child );
    }
    child.setParent ( this );
    if ( children == null )
    {
        children = new ArrayList<N> ();
    }
    children.add ( index, ( N ) child );
}
 
Example 2
Source File: ObjectTreeNode.java    From bigtable-sql with Apache License 2.0 4 votes vote down vote up
public void add(MutableTreeNode newChild)
{
   super.add(newChild);
   newChild.setParent(this);
}