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

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

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

JTree.setSelectionPaths介绍

暂无

代码示例

代码示例来源:origin: org.codeartisans.swing-on-steroids/sos-ui-swing

@Override
public void setValue( Collection<?> value )
{
  List<TreePath> paths = new ArrayList<TreePath>();
  for ( Object obj : value ) {
    TreePath path = findObject( ( TreeNode ) tree.getModel().getRoot(), obj );
    if ( path != null ) {
      paths.add( path );
    }
  }
  tree.setSelectionPaths( paths.toArray( new TreePath[]{} ) );
}

代码示例来源:origin: com.mgmtp.jfunk/jfunk-core

private boolean readState() {
  ObjectInputStream ois = null;
  try {
    ois = new ObjectInputStream(new FileInputStream("jFunkFrame.state"));
    setBounds((Rectangle) ois.readObject());
    setExtendedState(ois.readInt());
    tree.setSelectionPaths((TreePath[]) ois.readObject());
    jFunkPropertyFilesComboBox.setSelectedIndex(ois.readInt());
    testSystemsComboBox.setSelectedIndex(ois.readInt());
    mailConfigurationsComboBox.setSelectedIndex(ois.readInt());
    threadCountComboBox.setSelectedIndex(ois.readInt());
    parallelComboBox.setSelectedIndex(ois.readInt());
    return true;
  } catch (final FileNotFoundException ex) {
    log.warn("Could not find saved state (which is fine during first start)");
    return false;
  } catch (final Exception ex) {
    log.error("Error reading state", ex);
    return false;
  } finally {
    IOUtils.closeQuietly(ois);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

/** Shows selection to reflect the current state of the selection in the explorer.
*
* @param paths array of paths that should be selected
*/
protected void showSelection(TreePath[] paths) {
  if (paths.length == 0) {
    tree.setSelectionPaths(new TreePath[0]);
  } else {
    tree.setSelectionPath(paths[0].getParentPath());
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public void run() {
    TreePath[] selectedPaths = tree.getSelectionPaths();
    firingChange = true;
    try {
      fireTableDataChanged();
    } finally {
      firingChange = false;
    }
    tree.setSelectionPaths(selectedPaths);
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public void treeCollapsed(TreeExpansionEvent event) {
    TreePath[] selectedPaths = tree.getSelectionPaths();
    fireTableDataChanged();
    tree.setSelectionPaths(selectedPaths);
  }
});

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

/** Shows selection to reflect the current state of the selection in the explorer.
*
* @param paths array of paths that should be selected
*/
protected void showSelection (TreePath[] paths) {
  if (paths.length == 0) {
    tree.setSelectionPaths (new TreePath[0]);
  } else {
    tree.setSelectionPath (paths[0].getParentPath ());
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public void treeExpanded(TreeExpansionEvent event) {
  TreePath[] selectedPaths = tree.getSelectionPaths();
  fireTableDataChanged();
  tree.setSelectionPaths(selectedPaths);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

/** Shows selection to reflect the current state of the selection in the explorer.
*
* @param paths array of paths that should be selected
*/
protected void showSelection (TreePath[] paths) {
  if (paths.length == 0) {
    tree.setSelectionPaths (new TreePath[0]);
  } else {
    tree.setSelectionPath (paths[0].getParentPath ());
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-propertyeditors

protected void handleDeselectAction(ActionEvent event) {
  TreePath paths[], path;
  paths = selectedJTree.getSelectionPaths();
  for (int i = 0; i < paths.length; i++) {
    path = paths[i];
    removePath(path);
  }
  selectedJTree.setSelectionPaths(null);
}

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

/**
 * Selects under a given parent all the nodes whose name contains a given substring.
 * This method will throw an exception if no the parent path was invalid or if no children
 * were found.
 */
public void select(String parentPath, String childSubstring) {
 TreePath jTreePath = getTreePath(parentPath);
 TreeModel model = jTree.getModel();
 Object node = jTreePath.getLastPathComponent();
 List<TreePath> subPaths = new ArrayList<TreePath>();
 for (int i = 0, max = model.getChildCount(node); i < max; i++) {
  Object child = model.getChild(node, i);
  String text = getShownText(child);
  if (text.indexOf(childSubstring) >= 0) {
   subPaths.add(jTreePath.pathByAddingChild(child));
  }
 }
 if (subPaths.isEmpty()) {
  AssertAdapter.fail("No children found");
 }
 TreePath[] result = subPaths.toArray(new TreePath[subPaths.size()]);
 jTree.setSelectionPaths(result);
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

private void updateNodes() {
    Node[] nodes = new Node[tree.getRowCount()];
    for (int i = 0; i < tree.getRowCount(); i++) {
      nodes[i] = Visualizer.findNode(tree.getPathForRow(i).getLastPathComponent());
    }
    setNodes(nodes);
    // retore selection paths
    if (tps != null) {
      tree.setSelectionPaths(tps);
      tps = null;
    }
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

private void updateNodes() {
    Node[] nodes = new Node[tree.getRowCount()];
    for (int i = 0; i < tree.getRowCount(); i++) {
      nodes[i] = Visualizer.findNode(tree.getPathForRow(i).getLastPathComponent());
    }
    setNodes(nodes);
    // retore selection paths
    if (tps != null) {
      tree.setSelectionPaths (tps);
      tps = null;
    }
  }
}

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

@Override
public void run(ProgressMonitor pm) {
    List<TreePath> dropPaths = new ArrayList<TreePath>(draggedResources.size());
    for (int i = 0; i < draggedResources.size(); i++) {
        String sourceName = draggedResources.get(i).getId();
        if (pm.isCancelled()) {
            break;
        } else {
            pm.progressTo(100 * i / draggedResources.size());
            try {
                  ILayer nl = mapContext.createLayer(sourceName);
                  dropNode.insertLayer(nl, dropIndex);
                  dropPaths.add(getPathFromNode(new TocTreeNodeLayer(nl)));
            } catch (Exception e) {
                throw new RuntimeException(I18N.tr("Cannot add the layer to the destination"), e);
            }
        }
    }
    treeModel.nodeChanged(new TocTreeNodeLayer(dropNode));
    // Select the new layer(s) if there is no selection
    if(tree.getSelectionCount()==0) {
      tree.setSelectionPaths(dropPaths.toArray(new TreePath[dropPaths.size()]));
    }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

private void updateNodes() {
    Node[] nodes = new Node[tree.getRowCount()];
    for (int i = 0; i < tree.getRowCount(); i++) {
      nodes[i] = Visualizer.findNode(tree.getPathForRow(i).getLastPathComponent());
    }
    setNodes(nodes);
    // retore selection paths
    if (tps != null) {
      tree.setSelectionPaths (tps);
      tps = null;
    }
  }
}

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

private void setTocSelection(MapContext mapContext) {
    ILayer[] layers = mapContext.getSelectedLayers();
    Style[] styles = mapContext.getSelectedStyles();
    TreePath[] selectedPaths = new TreePath[layers.length + styles.length];
    for (int i = 0; i < layers.length; i++) {
        
        selectedPaths[i] = new TreePath(createTreeNodeArray(layers[i].getLayerPath()));
    }
    for (int i = 0; i < styles.length; i++) {
        Style s = styles[i];
        TreeNode[] lays = createTreeNodeArray(s.getLayer().getLayerPath());
        TreeNode[] path = new TreeNode[lays.length + 1];
        System.arraycopy(lays, 0, path, 0, lays.length);
        path[path.length - 1] = new TocTreeNodeStyle(s);
        selectedPaths[i + layers.length] = new TreePath(path);
    }
    fireSelectionEvent.set(false);
    try {
        tree.setSelectionPaths(selectedPaths);
    } finally {
        fireSelectionEvent.set(true);
    }
}

代码示例来源:origin: dsukhoroslov/bagri

private void removeSelectedDocument() {
  DefaultMutableTreeNode nextNode;
  DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) docTree.getLastSelectedPathComponent();
  if (selectedNode.getNextSibling() != null) {
    nextNode = selectedNode.getNextSibling();
  } else if (selectedNode.getPreviousSibling() != null) {
    nextNode = selectedNode.getPreviousSibling();
  } else {
    nextNode = (DefaultMutableTreeNode) selectedNode.getParent();
  }
  ((DefaultTreeModel) docTree.getModel()).removeNodeFromParent(selectedNode);
  docTree.setSelectionPaths(new TreePath[] {new TreePath(nextNode.getPath())});
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public void run() {
    List pathState = getExpandedPaths();
    TreePath[] selectedPaths = tree.getSelectionPaths();
    treeTableModel.setRoot(newRoot);
    tree.getSelectionModel().clearSelection();
    treeTableModel.fireTreeStructureChanged(this,
                        treeTableModel.getPathToRoot((CCTNode) treeTableModel.getRoot()),
                        null, null);
    if (selectedPaths != null)
      for (int i = 0; i < selectedPaths.length; i++)
        selectedPaths[i] = getCurrentPath(selectedPaths[i]);
    List expandedPaths = new ArrayList();
    for (Object tp : pathState)
      expandedPaths.add(getCurrentPath((TreePath)tp));
    tree.setSelectionPaths(selectedPaths);
    restoreExpandedPaths(expandedPaths);
    treeTable.getTableHeader().repaint();
    delayedFireTableDataChanged();
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public void run() {
    List pathState = getExpandedPaths();
    TreePath[] selectedPaths = tree.getSelectionPaths();
    tree.getSelectionModel().clearSelection();
    treeTableModel.fireTreeStructureChanged(this,
        treeTableModel.getPathToRoot((CCTNode) treeTableModel.getRoot()),
        null, null);
    
    if (selectedPaths != null)
      for (int i = 0; i < selectedPaths.length; i++)
        selectedPaths[i] = getCurrentPath(selectedPaths[i]);
    tree.setSelectionPaths(selectedPaths);
    restoreExpandedPaths(pathState);
    treeTable.getTableHeader().repaint();
    delayedFireTableDataChanged();
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-propertyeditors

protected void handleUpAction(ActionEvent event) {
  TreePath paths[] = selectedJTree.getSelectionPaths();
  sortTreePaths(paths);
  for (int i = 0; i < paths.length; i++) {
    TreePath path = paths[i];
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent();
    int index = parent.getIndex(node);
    if (index == 0) {
      continue;
    }
    DefaultMutableTreeNode removed = (DefaultMutableTreeNode)parent.getChildAt(index);
    boolean wasExpanded = selectedJTree.isExpanded(path);
    selectedJTreeModel.removeNodeFromParent(removed);
    selectedJTreeModel.insertNodeInto(removed, parent, index - 1);
    if (wasExpanded && removed.getChildCount() > 0) {
      DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode)removed.getFirstChild();
      selectedJTree.makeVisible(new TreePath(firstChild.getPath()));
    }
  }
  selectedJTree.setSelectionPaths(paths);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-propertyeditors

protected void handleDownAction(ActionEvent event) {
  TreePath[] paths = selectedJTree.getSelectionPaths();
  sortTreePaths(paths);
  for (int i = paths.length - 1; i >= 0; i--) {
    TreePath path = paths[i];
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent();
    int index = parent.getIndex(node);
    if ((index + 1) == parent.getChildCount()) {
      continue;
    }
    DefaultMutableTreeNode removed = (DefaultMutableTreeNode)parent.getChildAt(index);
    boolean wasExpanded = selectedJTree.isExpanded(path);
    selectedJTreeModel.removeNodeFromParent(removed);
    selectedJTreeModel.insertNodeInto(removed, parent, index + 1);
    if (wasExpanded && removed.getChildCount() > 0) {
      DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode)removed.getFirstChild();
      selectedJTree.makeVisible(new TreePath(firstChild.getPath()));
    }
  }
  selectedJTree.setSelectionPaths(paths);
}

相关文章

JTree类方法