Exemple #1
0
 public static ActionCallback selectPath(final JTree tree, final TreePath path, boolean center) {
   tree.makeVisible(path);
   if (center) {
     return showRowCentred(tree, tree.getRowForPath(path));
   } else {
     final int row = tree.getRowForPath(path);
     return showAndSelect(
         tree, row - ListScrollingUtil.ROW_PADDING, row + ListScrollingUtil.ROW_PADDING, row, -1);
   }
 }
Exemple #2
0
  public static void ensureSelection(JTree tree) {
    final TreePath[] paths = tree.getSelectionPaths();

    if (paths != null) {
      for (TreePath each : paths) {
        if (tree.getRowForPath(each) >= 0 && tree.isVisible(each)) {
          return;
        }
      }
    }

    for (int eachRow = 0; eachRow < tree.getRowCount(); eachRow++) {
      TreePath eachPath = tree.getPathForRow(eachRow);
      if (eachPath != null && tree.isVisible(eachPath)) {
        tree.setSelectionPath(eachPath);
        break;
      }
    }
  }
Exemple #3
0
 private static int getSelectedRow(final JTree tree) {
   return tree.getRowForPath(tree.getSelectionPath());
 }