Java JTree upMove(JTree tree)

Here you can find the source of upMove(JTree tree)

Description

up Move

License

Open Source License

Declaration

public static void upMove(JTree tree) 

Method Source Code

//package com.java2s;
/*//  w w  w.j a v a 2 s  . c o  m
 * Copyright (C) 2006-2009
 * Woei-Kae Chen <wkc@csie.ntut.edu.tw>
 * Hung-Shing Chao <s9598007@ntut.edu.tw>
 * Tung-Hung Tsai <s159020@ntut.edu.tw>
 * Zhe-Ming Zhang <s2598001@ntut.edu.tw>
 * Zheng-Wen Shen <zwshen0603@gmail.com>
 * Jung-Chi Wang <snowwolf725@gmail.com>
 *
 * This file is part of GTT (GUI Testing Tool) Software.
 *
 * GTT is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GTT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * GNU GENERAL PUBLIC LICENSE http://www.gnu.org/licenses/gpl
 */

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.tree.TreePath;

public class Main {
    public static void upMove(JTree tree) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
                .getLastSelectedPathComponent();
        if (node == null)
            return;
        if (node.isRoot())
            return;

        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node
                .getParent();
        int index = parent.getIndex(node);
        if (index <= 0)
            return;
        parent.remove(node);
        parent.insert(node, index - 1);

        TreePath path = tree.getSelectionPath();
        tree.setSelectionPath(path);
        tree.updateUI();
    }
}

Related

  1. setComponentTreeEnabled(Component c, boolean enabled)
  2. setLeftChildIndent(JTree tree, int indent)
  3. setToolTipOnTree(Container c, String tooltip)
  4. setTreeEnabled(Container container, boolean enabled)
  5. treeListen(final ActionListener listener)