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

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

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

JTree.scrollPathToVisible介绍

暂无

代码示例

代码示例来源:origin: skylot/jadx

private void syncWithEditor() {
  ContentPanel selectedContentPanel = tabbedPane.getSelectedCodePanel();
  if (selectedContentPanel == null) {
    return;
  }
  JNode node = selectedContentPanel.getNode();
  if (node.getParent() == null && treeRoot != null) {
    // node not register in tree
    node = treeRoot.searchClassInTree(node);
    if (node == null) {
      LOG.error("Class not found in tree");
      return;
    }
  }
  TreeNode[] pathNodes = treeModel.getPathToRoot(node);
  if (pathNodes == null) {
    return;
  }
  TreePath path = new TreePath(pathNodes);
  tree.setSelectionPath(path);
  tree.makeVisible(path);
  tree.scrollPathToVisible(path);
  tree.requestFocus();
}

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

/**
 * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
 */
@Override
public void viewerModelChanged(ViewerModelEvent e) {
  switch (e.getReason()) {
  case ViewerModelEvent.CODE_RECOMPILED:
    tree.setModel(new ASTModel(model.getRootNode()));
    break;
  case ViewerModelEvent.NODE_SELECTED:
    if (e.getSource() != this) {
      List<Node> list = new ArrayList<>();
      for (Node n = (Node) e.getParameter(); n != null; n = n.jjtGetParent()) {
        list.add(n);
      }
      Collections.reverse(list);
      TreePath path = new TreePath(list.toArray());
      tree.setSelectionPath(path);
      tree.scrollPathToVisible(path);
    }
    break;
  default:
    // Do nothing
    break;
  }
}

代码示例来源:origin: INRIA/spoon

public void setVisible(DefaultMutableTreeNode node) {
  TreePath path = new TreePath(node.getPath());
  getJTree().scrollPathToVisible(path);
  getJTree().setSelectionPath(path);
}

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

@Override
  public void actionPerformed(ActionEvent actionEvent)
  {
    TreePath path = statusObj.getPathForString(statusField.getText());
    if (path != null)
    {
      tree.setSelectionPath(path);
      tree.scrollPathToVisible(path);
      tree.requestFocusInWindow();
    }
    else
    {
      statusField.setBorder(errorBorder);
    }
  }
};

代码示例来源:origin: pentaho/mondrian

/**
 * Updates the tree display after an Add / Delete operation.
 */
private void refreshTree(TreePath path) {
  setDirty(true);
  if (!dirtyFlag) {
    setDirtyFlag(true);   // dirty indication shown on title
    setTitle();
  }
  updater.update();
  tree.scrollPathToVisible(path);
}

代码示例来源:origin: org.sonarsource.sslr/sslr-toolkit

@Override
public void scrollAstTo(@Nullable AstNode astNode) {
 if (astNode != null) {
  DefaultMutableTreeNode treeNode = getAstTreeNodeWithGivenUserObject((DefaultMutableTreeNode) astTree.getModel().getRoot(), astNode);
  astTree.scrollPathToVisible(new TreePath(treeNode.getPath()));
 }
}

代码示例来源:origin: org.boofcv/boofcv-swing

@Override
public void insertUpdate(DocumentEvent e) {
  String text = searchBox.getText();
  DefaultMutableTreeNode selection = (DefaultMutableTreeNode) tree.getModel().getRoot();
  TreePath path = searchTree(text, selection, true);
  if (path != null) {
    tree.setSelectionPath(path);
    tree.scrollPathToVisible(path);
  } else {
    tree.setSelectionPath(null);
  }
}

代码示例来源:origin: aterai/java-swing-tips

@Override public void actionPerformed(ActionEvent e) {
  JTree tree = (JTree) getInvoker();
  DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
  DefaultMutableTreeNode parent = (DefaultMutableTreeNode) path.getLastPathComponent();
  DefaultMutableTreeNode child = new DefaultMutableTreeNode("New node");
  model.insertNodeInto(child, parent, parent.getChildCount());
  tree.scrollPathToVisible(new TreePath(child.getPath())); // https://ateraimemo.com/Swing/ScrollRectToVisible.html
 }
};

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

public void mouseClicked(MouseEvent e){
    if (SwingUtilities.isRightMouseButton(e)){
      TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
      tree.setSelectionPath(path);
      tree.scrollPathToVisible(path);
      popup.show(tree, e.getX(), e.getY());
    }
  }
});

代码示例来源:origin: edu.stanford.protege/jtreetable

@Override
  public void valueChanged(TreeSelectionEvent event) {
    JTreeTable.this.tree.scrollPathToVisible(event.getPath());
    syncScrollers(treeScrollPane, tableScrollPane);
  }
});

代码示例来源:origin: locationtech/jts

public void moveToNextNode(int direction) {
 direction = (int) Math.signum(direction);
 TreePath path = tree.getSelectionPath();
 
 TreePath nextPath2 = nextPath(path, 2 * direction);
 tree.scrollPathToVisible(nextPath2);
 
 TreePath nextPath = nextPath(path, direction);
 tree.setSelectionPath(nextPath);
}

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

@Override
public void elementAdded(QueryControllerEntity element) {
  String elementId = element.getID();
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) queryControllerModel.getNode(elementId);
  // Select the new node in the JTree
  treSavedQuery.setSelectionPath(new TreePath(node.getPath()));
  treSavedQuery.scrollPathToVisible(new TreePath(node.getPath()));
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

public void select( JTree tree )
{
 TreePath path = getPath();
 tree.expandPath( path );
 tree.setSelectionPath( path );
 tree.scrollPathToVisible( path );
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

public void select( JTree tree )
{
 TreePath path = getPath();
 tree.expandPath( path );
 tree.setSelectionPath( path );
 tree.scrollPathToVisible( path );
}

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

@Override
  public void elementChanged(QueryControllerQuery query) {
    String queryId = query.getID();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) queryControllerModel.getNode(queryId);
    
    // Select the modified node in the JTree
    treSavedQuery.setSelectionPath(new TreePath(node.getPath()));
    treSavedQuery.scrollPathToVisible(new TreePath(node.getPath()));
  }
}

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

@Override
public void elementChanged(QueryControllerQuery query, QueryControllerGroup group) {
  String queryId = query.getID();
  String groupId = group.getID();
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) queryControllerModel.getElementQuery(queryId, groupId);
      
  // Select the modified node in the JTree
  treSavedQuery.setSelectionPath(new TreePath(node.getPath()));
  treSavedQuery.scrollPathToVisible(new TreePath(node.getPath()));
}

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

@Override
public void elementAdded(QueryControllerQuery query, QueryControllerGroup group) {
  String queryId = query.getID();
  String groupId = group.getID();
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) queryControllerModel.getElementQuery(queryId, groupId);
      
  // Select the new node in the JTree
  treSavedQuery.setSelectionPath(new TreePath(node.getPath()));
  treSavedQuery.scrollPathToVisible(new TreePath(node.getPath()));
}

代码示例来源:origin: org.apache.uima/uimaj-tools

@Override
public void actionPerformed(ActionEvent e) {
 FSTreeModel treeModel = (FSTreeModel) this.main.getFsTree().getModel();
 TreePath path = treeModel.pathToNode(this.node);
 this.main.getFsTree().setSelectionPath(path);
 this.main.getFsTree().scrollPathToVisible(path);
}

代码示例来源:origin: GumTreeDiff/gumtree

private void openNodes() {
  for (ITree t: classifyTrees.getSrcDelTrees()) openNode(panSrc, t);
  for (ITree t: classifyTrees.getDstAddTrees()) openNode(panDst, t);
  for (ITree t: classifyTrees.getSrcUpdTrees()) openNode(panSrc, t);
  for (ITree t: classifyTrees.getDstUpdTrees()) openNode(panDst, t);
  for (ITree t: classifyTrees.getSrcMvTrees()) openNode(panSrc, t);
  for (ITree t: classifyTrees.getDstMvTrees()) openNode(panDst, t);
  panSrc.getJTree().scrollPathToVisible(new TreePath(panSrc.getTrees().get(src.getRoot()).getPath()));
  panDst.getJTree().scrollPathToVisible(new TreePath(panDst.getTrees().get(dst.getRoot()).getPath()));
}

代码示例来源:origin: com.github.gumtreediff/client.diff

private void openNodes() {
  for (ITree t: classifyTrees.getSrcDelTrees()) openNode(panSrc, t);
  for (ITree t: classifyTrees.getDstAddTrees()) openNode(panDst, t);
  for (ITree t: classifyTrees.getSrcUpdTrees()) openNode(panSrc, t);
  for (ITree t: classifyTrees.getDstUpdTrees()) openNode(panDst, t);
  for (ITree t: classifyTrees.getSrcMvTrees()) openNode(panSrc, t);
  for (ITree t: classifyTrees.getDstMvTrees()) openNode(panDst, t);
  panSrc.getJTree().scrollPathToVisible(new TreePath(panSrc.getTrees().get(src.getRoot()).getPath()));
  panDst.getJTree().scrollPathToVisible(new TreePath(panDst.getTrees().get(dst.getRoot()).getPath()));
}

相关文章

JTree类方法