当前位置: 首页>>代码示例>>Java>>正文


Java JTree.getSelectionPaths方法代码示例

本文整理汇总了Java中javax.swing.JTree.getSelectionPaths方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.getSelectionPaths方法的具体用法?Java JTree.getSelectionPaths怎么用?Java JTree.getSelectionPaths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTree的用法示例。


在下文中一共展示了JTree.getSelectionPaths方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateJTree

import javax.swing.JTree; //导入方法依赖的package包/类
public static JTree updateJTree(JTree tree, TreeArrayList<?> data, ExpandedPaths ep) {
    ArrayList<String> expanded_paths = null;
    TreePath[] paths = null;
    if(ep != null) {
        expanded_paths = ep.getExpandedPaths(tree);
        paths = tree.getSelectionPaths();
    }
    DefaultMutableTreeNode top = getDefaultMutableTreeNodeOfHashMap(data);
    DefaultTreeModel model = new DefaultTreeModel(top);
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    model.reload(root);
    tree.setModel(model);
    if(ep != null) {
        ep.expandPaths(tree, expanded_paths);
        tree.setSelectionPaths(paths);
    }
    return tree;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:19,代码来源:JTreeUtils.java

示例2: createTransferable

import javax.swing.JTree; //导入方法依赖的package包/类
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree)c;
    TreePath[] paths = tree.getSelectionPaths();
    if(paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies =
            new ArrayList<DefaultMutableTreeNode>();
        List<DefaultMutableTreeNode> toRemove =
            new ArrayList<DefaultMutableTreeNode>();
        DefaultMutableTreeNode node =
            (DefaultMutableTreeNode)paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for(int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next =
                (DefaultMutableTreeNode)paths[i].getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if(next.getLevel() < node.getLevel()) {
                break;
            } else if(next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes =
            copies.toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove =
            toRemove.toArray(new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:39,代码来源:TreeTransferHandler.java

示例3: createTransferable

import javax.swing.JTree; //导入方法依赖的package包/类
@Override
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree) c;
    TreePath[] paths = tree.getSelectionPaths();
    if (paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies = new ArrayList<>();
        List<DefaultMutableTreeNode> toRemove = new ArrayList<>();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for (int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next = (DefaultMutableTreeNode) paths[i]
                    .getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if (next.getLevel() < node.getLevel()) {
                break;
            } else if (next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes = copies
                .toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove = toRemove.toArray(
                new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:LastNodeLowerHalfDrop.java

示例4: getStringComonAncestor

import javax.swing.JTree; //导入方法依赖的package包/类
public static List<String> getStringComonAncestor(JTree tree) {
	List<String> selectedFiles = new ArrayList<String>();
	TreePath[] selectedPaths = tree.getSelectionPaths();
	List<TreePath> commonAncestors = TreeFormatter.getTreeCommonAncestors(selectedPaths);
	String fullPath = "";
	for (TreePath treePath : commonAncestors) {
		fullPath = TreeFormatter.getStringPath(treePath);
		selectedFiles.add(fullPath);
	}
	return selectedFiles;
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:12,代码来源:TreeFormatter.java

示例5: getUIState

import javax.swing.JTree; //导入方法依赖的package包/类
static UIState getUIState(JTree tree) {
    TreePath[] selectedPaths = tree.getSelectionPaths();
    TreePath rootPath = new TreePath(tree.getModel().getRoot());
    Enumeration<TreePath> expandedPaths = tree.getExpandedDescendants(rootPath);
    return new UIState(selectedPaths, expandedPaths);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ProfilerTreeTable.java


注:本文中的javax.swing.JTree.getSelectionPaths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。