javax.swing.JTree.addSelectionPath()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中javax.swing.JTree.addSelectionPath()方法的一些代码示例,展示了JTree.addSelectionPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.addSelectionPath()方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:addSelectionPath

JTree.addSelectionPath介绍

暂无

代码示例

代码示例来源:origin: UISpec4J/UISpec4J

/**
 * Expands the current jTree selection with a given node.
 */
public void addToSelection(String path) {
 jTree.addSelectionPath(getTreePath(path));
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-runtime

@Override
public void addSelectionPath(TreePath path) {
  getUI().addSelectionPath(path);
}

代码示例来源:origin: UISpec4J/UISpec4J

/**
 * Expands the current jTree selection with a node identified by its position in its parent node.
 * <p>This method is preferred over {@link #addToSelection(String)} when there are several nodes
 * with the same name under a given parent.
 */
public void addToSelection(String parentPath, int childIndex) {
 jTree.addSelectionPath(computeChildTreePath(parentPath, childIndex));
}

代码示例来源:origin: UISpec4J/UISpec4J

public void select(String[] paths) {
 jTree.clearSelection();
 for (String path : paths) {
  jTree.addSelectionPath(getTreePath(path));
 }
}

代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik

public void mousePressed(MouseEvent e) {
  JTree sourceTree = (JTree) e.getSource();
  TreePath targetPath = sourceTree.getPathForLocation(e.getX(), e
      .getY());
  if (!e.isControlDown() && !e.isShiftDown()) {
    sourceTree.setSelectionPath(targetPath);
  } else {
    sourceTree.addSelectionPath(targetPath);
  }
  // Show the pop-up component
  if (e.isPopupTrigger() && e.getClickCount() == 1) {
    showPopUp(e);
  }
}

代码示例来源:origin: apache/batik

public void mousePressed(MouseEvent e) {
  JTree sourceTree = (JTree) e.getSource();
  TreePath targetPath = sourceTree.getPathForLocation(e.getX(), e
      .getY());
  if (!e.isControlDown() && !e.isShiftDown()) {
    sourceTree.setSelectionPath(targetPath);
  } else {
    sourceTree.addSelectionPath(targetPath);
  }
  // Show the pop-up component
  if (e.isPopupTrigger() && e.getClickCount() == 1) {
    showPopUp(e);
  }
}

代码示例来源:origin: UISpec4J/UISpec4J

/**
 * Sets the jTree selection on a node identified by its position in its parent node.
 * <p>This method is preferred over {@link #select(String)} when there are several nodes
 * with the same name under a given parent.
 */
public void select(String parentPath, int childIndex) {
 int childCount = getChildCount(parentPath);
 if (childIndex < 0 || childCount <= childIndex) {
  throw new RuntimeException("No child found under '" +
                parentPath +
                "' for index '" + childIndex + "'");
 }
 jTree.clearSelection();
 jTree.addSelectionPath(computeChildTreePath(parentPath, childIndex));
}

代码示例来源:origin: iamxiatian/xsimilarity

TreePath path = new TreePath(((DefaultTreeModel) jtree.getModel()).getPathToRoot(node));
jtree.expandPath(path);
jtree.addSelectionPath(path);
Object[] objs = path.getPath();
for (int i = objs.length - 1; i > 0; i--) {

代码示例来源:origin: sdedit/sdedit

public void restoreSelections(PathIdenter identer, List<String> selections) {
  tree.removeSelectionPaths(tree.getSelectionPaths());
  for (String selection : selections) {
    TreePath path = identer.getPath(selection);
    if (path != null) {
      tree.addSelectionPath(path);
    }
  }
}

代码示例来源:origin: org.orbisgis/toc

private void maybeShowPopup(MouseEvent e) {
        if (e.isPopupTrigger()) {
            //Update selection
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            TreePath[] selectionPaths = tree.getSelectionPaths();
            if (selectionPaths != null && path != null){
                if (!contains(selectionPaths, path)) {
                    if (e.isControlDown()) {
                        tree.addSelectionPath(path);
                    } else {
                        tree.setSelectionPath(path);
                    }
                }
            } else {
                tree.setSelectionPath(path);
            }
            //Show popup
            JPopupMenu menu = new JPopupMenu();
            popupActions.copyEnabledActions(menu);
            menu.show(e.getComponent(),
                e.getX(), e.getY());
        }
    }
}

代码示例来源:origin: org.codehaus.sonar.sslr/sslr-devkit

private void selectPath() {
 if (!EMPTY_TREE_MODEL.equals(astTree.getModel())) {
  int offset = codeEditor.getCaretPosition();
  int line = lineOffsets.getLineFromOffset(offset);
  int column = lineOffsets.getColumnFromOffsetAndLine(offset, line);
  int minimumOffset = Integer.MAX_VALUE;
  DefaultMutableTreeNode treeNode = null;
  Enumeration<DefaultMutableTreeNode> enumeration = ((DefaultMutableTreeNode) astTree.getModel().getRoot()).breadthFirstEnumeration();
  while (enumeration.hasMoreElements()) {
   DefaultMutableTreeNode treeNodeChild = enumeration.nextElement();
   if (getParentFromUserObject(treeNodeChild.getUserObject()) == null) {
    AstNode astNode = (AstNode) treeNodeChild.getUserObject();
    Token token = astNode.getToken();
    if ((token.getLine() > line || token.getLine() == line && token.getColumn() >= column) && lineOffsets.getStartOffset(token) < minimumOffset) {
     minimumOffset = lineOffsets.getStartOffset(token);
     treeNode = treeNodeChild;
    }
   }
  }
  astTree.clearSelection();
  if (treeNode != null) {
   astTree.addSelectionPath(new TreePath(treeNode.getPath()));
   highlightSelectedPaths();
  }
 }
}

代码示例来源:origin: com.google.code.findbugs/findbugs

void openPreviouslySelected(List<BugLeafNode> selected) {
  Debug.printf("Starting Open Previously Selected for %d nodes\n", selected.size());
  for (BugLeafNode b : selected) {
    try {
      BugInstance bug = b.getBug();
      TreePath path = getPathToBug(bug);
      if (path == null) {
        continue;
      }
      Debug.printf("Opening %s\n", path);
      mainFrame.getTree().expandPath(path.getParentPath());
      mainFrame.getTree().addSelectionPath(path);
    } catch (RuntimeException e) {
      Debug.println("Failure opening a selected node, node will not be opened in new tree");
    }
  }
}

代码示例来源:origin: com.jidesoft/jide-oss

@Override
protected void setSelectedIndex(int index, boolean incremental) {
  if (!isRecursive()) {
    if (incremental) {
      ((JTree) _component).addSelectionInterval(index, index);
    }
    else {
      ((JTree) _component).setSelectionRow(index);
    }
    ((JTree) _component).scrollRowToVisible(index);
  }
  else {
    Object elementAt = getElementAt(index);
    if (elementAt instanceof TreePath) { // else case should never happen
      TreePath path = (TreePath) elementAt;
      if (incremental) {
        ((JTree) _component).addSelectionPath(path);
      }
      else {
        ((JTree) _component).setSelectionPath(path);
      }
      ((JTree) _component).scrollPathToVisible(path);
    }
  }
}

代码示例来源:origin: net.sf.ingenias/editor

validate();
restoreTreeExpansionPath();
jt.addSelectionPath(new TreePath(node.getPath()));
validate();
restoreTreeExpansionPath();
jt.addSelectionPath(new TreePath(node.getPath()));

相关文章

JTree类方法