本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}