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

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

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

JTree.setSelectionPath介绍

暂无

代码示例

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

@Override
  public void mouseReleased(MouseEvent e) {
    if (e.isPopupTrigger()) {
      TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
      tree.setSelectionPath(path);
      JPopupMenu menu = new ASTNodePopupMenu(model, (Node) path.getLastPathComponent());
      menu.show(tree, e.getX(), e.getY());
    }
  }
});

代码示例来源: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: stackoverflow.com

tree.setSelectionPath(treePath);
tree.scrollRowToVisible(row);

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

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

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

protected void arrowButtonUpAction(ActionEvent evt) {
  TreePath tpath = tree.getSelectionPath();
  if (tpath != null) {
    TreePath parentpath = tpath.getParentPath();
    if (parentpath != null) {
      tree.setSelectionPath(parentpath);
      refreshTree(parentpath);
    }
  }
}

代码示例来源:origin: knowm/XChart

protected void init() {
 // Create the nodes.
 DefaultMutableTreeNode top = new DefaultMutableTreeNode("XChart Example Charts");
 createNodes(top);
 tree = new JTree(top);
 // Create a tree that allows one selection at a time.
 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
 // Listen for when the selection changes.
 tree.addTreeSelectionListener(this);
 // Create the scroll pane and add the tree to it.
 JScrollPane treeView = new JScrollPane(tree);
 // Create Chart Panel
 tabbedPane = new JTabbedPane();
 for (int i = 0; i < tree.getRowCount(); i++) {
  tree.expandRow(i);
 }
 // select first leaf
 DefaultMutableTreeNode firstLeaf = top.getFirstLeaf();
 tree.setSelectionPath(new TreePath(firstLeaf.getPath()));
 // Add the scroll panes to a split pane.
 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
 splitPane.setTopComponent(treeView);
 splitPane.setBottomComponent(tabbedPane);
 Dimension minimumSize = new Dimension(130, 160);
 treeView.setMinimumSize(minimumSize);
 splitPane.setPreferredSize(new Dimension(700, 700));
 // Add the split pane to this panel.
 add(splitPane);
}

代码示例来源: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

protected void moveLevelUp(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.Hierarchy hierarchy =
    (MondrianGuiDef.Hierarchy)
      info.parentPathObjs[info.parentPathObjs.length - 2];
  int loc = -1;
  for (int i = 0; i < hierarchy.levels.length; i++) {
    if (hierarchy.levels[i] == info.level) {
     loc = i;
     break;
    }
  }
  if (loc > 0) {
   MondrianGuiDef.Level tmp = hierarchy.levels[loc - 1];
   hierarchy.levels[loc - 1] = info.level;
   hierarchy.levels[loc] = tmp;
  }
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath);
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

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

protected void moveLevelDown(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.Hierarchy hierarchy =
    (MondrianGuiDef.Hierarchy)
      info.parentPathObjs[info.parentPathObjs.length - 2];
  int loc = -1;
  for (int i = 0; i < hierarchy.levels.length; i++) {
    if (hierarchy.levels[i] == info.level) {
     loc = i;
     break;
    }
  }
  if (loc < hierarchy.levels.length - 1) {
   MondrianGuiDef.Level tmp = hierarchy.levels[loc + 1];
   hierarchy.levels[loc + 1] = info.level;
   hierarchy.levels[loc] = tmp;
  }
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath);
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

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

protected void addMemberFormatter(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  final MondrianGuiDef.MemberFormatter formatter =
    new MondrianGuiDef.MemberFormatter();
  info.level.memberFormatter = formatter;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(formatter));
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

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

protected void addOrdinalExp(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.OrdinalExpression ordinalExp =
    new MondrianGuiDef.OrdinalExpression();
  ordinalExp.expressions = new MondrianGuiDef.SQL[1];    // min 1
  ordinalExp.expressions[0] = new MondrianGuiDef.SQL();
  ordinalExp.expressions[0].dialect = "generic";
  ordinalExp.expressions[0].cdata = "";
  info.level.ordinalExp = ordinalExp;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(ordinalExp));
  refreshTree(tree.getSelectionPath());
}

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

protected void addNameExp(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.NameExpression nameExp =
    new MondrianGuiDef.NameExpression();
  nameExp.expressions = new MondrianGuiDef.SQL[1];    // min 1
  nameExp.expressions[0] = new MondrianGuiDef.SQL();
  nameExp.expressions[0].dialect = "generic";
  nameExp.expressions[0].cdata = "";
  info.level.nameExp = nameExp;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(nameExp));
  refreshTree(tree.getSelectionPath());
}

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

protected void addCaptionExp(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.CaptionExpression captionExp =
    new MondrianGuiDef.CaptionExpression();
  captionExp.expressions = new MondrianGuiDef.SQL[1];    // min 1
  captionExp.expressions[0] = new MondrianGuiDef.SQL();
  captionExp.expressions[0].dialect = "generic";
  captionExp.expressions[0].cdata = "";
  info.level.captionExp = captionExp;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(captionExp));
  refreshTree(tree.getSelectionPath());
}

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

protected void addParentExp(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.ParentExpression parentExp =
    new MondrianGuiDef.ParentExpression();
  parentExp.expressions = new MondrianGuiDef.SQL[1];    // min 1
  parentExp.expressions[0] = new MondrianGuiDef.SQL();
  parentExp.expressions[0].dialect = "generic";
  parentExp.expressions[0].cdata = "";
  info.level.parentExp = parentExp;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(parentExp));
  refreshTree(tree.getSelectionPath());
}

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

protected void addKeyExp(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.KeyExpression keyExp =
    new MondrianGuiDef.KeyExpression();
  keyExp.expressions = new MondrianGuiDef.SQL[1];    // min 1
  keyExp.expressions[0] = new MondrianGuiDef.SQL();
  keyExp.expressions[0].dialect = "generic";
  keyExp.expressions[0].cdata = "";
  info.level.keyExp = keyExp;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(keyExp));
  refreshTree(tree.getSelectionPath());
}

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

protected void addRole(ActionEvent evt) {
  MondrianGuiDef.Schema schema =
    (MondrianGuiDef.Schema) tree.getModel().getRoot();
  MondrianGuiDef.Role role = new MondrianGuiDef.Role();
  role.name = "";
  role.schemaGrants = new MondrianGuiDef.SchemaGrant[0];
  // add cube to schema
  role.name =
    getNewName(
      getResourceConverter().getString(
        "schemaExplorer.newRole.title", "New Role"),
      schema.roles);
  NodeDef[] temp = schema.roles;
  schema.roles = new MondrianGuiDef.Role[temp.length + 1];
  for (int _i = 0; _i < temp.length; _i++) {
    schema.roles[_i] = (MondrianGuiDef.Role) temp[_i];
  }
  schema.roles[schema.roles.length - 1] = role;
  tree.setSelectionPath(
    (new TreePath(model.getRoot())).pathByAddingChild(
      role));
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

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

protected void addParameter(ActionEvent evt) {
  MondrianGuiDef.Schema schema =
    (MondrianGuiDef.Schema) tree.getModel().getRoot();
  MondrianGuiDef.Parameter parameter = new MondrianGuiDef.Parameter();
  parameter.name = "";
  // set the required fields
  parameter.name =
    getNewName(
      getResourceConverter().getString(
        "schemaExplorer.newParameter.title", "New Parameter"),
      schema.parameters);
  // set the default values
  parameter.type = "String";
  parameter.modifiable = Boolean.TRUE;
  NodeDef[] temp = schema.parameters;
  schema.parameters = new MondrianGuiDef.Parameter[temp.length + 1];
  for (int _i = 0; _i < temp.length; _i++) {
    schema.parameters[_i] = (MondrianGuiDef.Parameter) temp[_i];
  }
  schema.parameters[schema.parameters.length - 1] = parameter;
  tree.setSelectionPath(
    (new TreePath(model.getRoot())).pathByAddingChild(
      parameter));
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

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

protected void addUserDefinedFunction(ActionEvent evt) {
  MondrianGuiDef.Schema schema =
    (MondrianGuiDef.Schema) tree.getModel().getRoot();
  MondrianGuiDef.UserDefinedFunction udf =
    new MondrianGuiDef.UserDefinedFunction();
  udf.name = "";
  udf.name =
    getNewName(
      getResourceConverter().getString(
        "schemaExplorer.newUserDefinedFunction.title",
        "New User defined Function"),
      schema.userDefinedFunctions);
  NodeDef[] temp = schema.userDefinedFunctions;
  schema.userDefinedFunctions =
    new MondrianGuiDef.UserDefinedFunction[temp.length + 1];
  for (int _i = 0; _i < temp.length; _i++) {
    schema.userDefinedFunctions[_i] =
      (MondrianGuiDef.UserDefinedFunction) temp[_i];
  }
  schema.userDefinedFunctions[schema.userDefinedFunctions.length - 1] =
    udf;
  tree.setSelectionPath(
    new TreePath(model.getRoot()).pathByAddingChild(
      udf));
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

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

protected void addProperty(ActionEvent evt) {
  final LevelInfo info = getSelectedLevel(evt);
  if (info == null) {
    return;
  }
  MondrianGuiDef.Property property = new MondrianGuiDef.Property();
  property.name = "";
  if (info.level.properties == null) {
    info.level.properties = new MondrianGuiDef.Property[0];
  }
  property.name =
    getNewName(
      getResourceConverter().getString(
        "schemaExplorer.newProperty.title",
        "New Property"),
      info.level.properties);
  NodeDef[] temp = info.level.properties;
  info.level.properties = new MondrianGuiDef.Property[temp.length + 1];
  for (int i = 0; i < temp.length; i++) {
    info.level.properties[i] = (MondrianGuiDef.Property) temp[i];
  }
  info.level.properties[info.level.properties.length - 1] = property;
  TreePath parentPath = new TreePath(info.parentPathObjs);
  tree.setSelectionPath(parentPath.pathByAddingChild(property));
  refreshTree(tree.getSelectionPath());
  setTableCellFocus(0);
}

相关文章

JTree类方法