Java Code Examples for javax.swing.JTree#getRowCount()

The following examples show how to use javax.swing.JTree#getRowCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static void previousRow(JTree tree) {
    int rowCount = tree.getRowCount();
    if (rowCount > 0) {
        int selectedRow = tree.getSelectionModel().getMinSelectionRow();
        if (selectedRow == -1) {
            selectedRow = (rowCount -1);
        } else {
            selectedRow--;
            if (selectedRow < 0) {
                selectedRow = (rowCount -1);
            }
        }
        tree.setSelectionRow(selectedRow);
        scrollTreeToSelectedRow(tree);
    }
}
 
Example 2
Source File: ExplainDialogFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private JTree createExplanationTree() {
  DefaultMutableTreeNode top = createNode(explanation);
  traverse(top, explanation.getDetails());

  JTree tree = new JTree(top);
  tree.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
  renderer.setOpenIcon(null);
  renderer.setClosedIcon(null);
  renderer.setLeafIcon(null);
  tree.setCellRenderer(renderer);
  // expand all nodes
  for (int row = 0; row < tree.getRowCount(); row++) {
    tree.expandRow(row);
  }
  return tree;
}
 
Example 3
Source File: RepositoryTreeUtil.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Saves the currently selected paths and saves all expanded repositories and nodes.
 *
 * @param tree
 *            The related tree, containing the path(s)
 */
public void saveExpansionState(JTree tree) {


	expandedNodes = new LinkedHashSet<>();
	selectedNodes = new LinkedHashSet<>();

	for (int i = 0; i < tree.getRowCount(); i++) {
		TreePath path = tree.getPathForRow(i);
		boolean isExpanded = tree.isExpanded(path);
		boolean isSelected = tree.isPathSelected(path);
		Object entryObject = path.getLastPathComponent();
		if ((isExpanded || isSelected) && entryObject instanceof Entry) {
			Entry entry = (Entry) entryObject;
			RepositoryLocation absoluteLocation = entry.getLocation();
			if (isExpanded) {
				expandedNodes.add(absoluteLocation);
			}
			if (isSelected) {
				selectedNodes.add(absoluteLocation);
			}
		}
	}

}
 
Example 4
Source File: AbstractObjectEditor.java    From cst with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void expandAllNodes(JTree tree, int startingIndex, int rowCount){
   for(int i=startingIndex;i<rowCount;++i){
      tree.expandRow(i);
   }
   if(tree.getRowCount()!=rowCount){
      expandAllNodes(tree, rowCount, tree.getRowCount());
   }
}
 
Example 5
Source File: TreeManager.java    From cst with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static  void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
    for (int i = startingIndex; i < rowCount; ++i) {
        tree.expandRow(i);
    }
    if (tree.getRowCount() != rowCount) {
        expandAllNodes(tree, rowCount, tree.getRowCount());
    }
}
 
Example 6
Source File: TDA.java    From tda with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * expand all nodes of the currently selected category, only works for tree categories.
 */
private void expandAllCatNodes(boolean expand) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    JTree catTree = (JTree) ((TreeCategory) node.getUserObject()).getCatComponent(this);
        if(expand) {
      for (int i = 0; i < catTree.getRowCount(); i++) {
            catTree.expandRow(i);
      }
        } else {
      for (int i = 0; i < catTree.getRowCount(); i++) {
            catTree.collapseRow(i);
        }
    }
}
 
Example 7
Source File: SpatialtoolboxController.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private void expandAllNodes( JTree tree, int startingIndex, int rowCount ) {
    for( int i = startingIndex; i < rowCount; ++i ) {
        tree.expandRow(i);
    }

    if (tree.getRowCount() != rowCount) {
        expandAllNodes(tree, rowCount, tree.getRowCount());
    }
}
 
Example 8
Source File: FabricMainWindow.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
private static JPanel createTreePanel(FabricStatusNode rootNode, FabricTreeWarningLevel minimumWarningLevel,
	IconSet iconSet) {
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

	TreeNode treeNode = new CustomTreeNode(null, rootNode, minimumWarningLevel);

	DefaultTreeModel model = new DefaultTreeModel(treeNode);
	JTree tree = new JTree(model);
	tree.setRootVisible(false);

	for (int row = 0; row < tree.getRowCount(); row++) {
		if (!tree.isVisible(tree.getPathForRow(row))) {
			continue;
		}

		CustomTreeNode node = ((CustomTreeNode) tree.getPathForRow(row).getLastPathComponent());

		if (node.node.expandByDefault || node.node.getMaximumWarningLevel().isAtLeast(FabricTreeWarningLevel.WARN)) {
			tree.expandRow(row);
		}
	}

	ToolTipManager.sharedInstance().registerComponent(tree);
	tree.setCellRenderer(new CustomTreeCellRenderer(iconSet));

	JScrollPane scrollPane = new JScrollPane(tree);
	panel.add(scrollPane);

	return panel;
}
 
Example 9
Source File: TreeKeyListener.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
protected boolean changeSelectionUsingText(KeyEvent e, String inputStr) {
	inputStr = inputStr.toUpperCase();
	JTree tree = (JTree) e.getComponent();

	int[] selection = tree.getSelectionRows();
	Arrays.sort(selection);
	int i = selection.length > 0 ? selection[selection.length - 1] : 0;
	int rowCount = tree.getRowCount();
	for (int offset = 0; offset < rowCount; offset++) {
		int row = (i + offset) % rowCount;
		TreePath path = tree.getPathForRow(row);
		TreeNode node = (TreeNode) path.getLastPathComponent();
		Component renderer = tree.getCellRenderer()
				.getTreeCellRendererComponent(tree, node, false,
						tree.isExpanded(path), node.isLeaf(), row,
						tree.isFocusOwner());
		String str = getText(renderer);
		if (str != null && str.length() >= 0
				&& str.toUpperCase().startsWith(inputStr)) {
			tree.setSelectionPath(path);
			return true;
		}
	}

	return false;
}
 
Example 10
Source File: StoredObjectsTreeModel.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
public static void getTreeExpansionState (JTree tree, List<TreePath> list)
{
	if (list == null)
		return ;
	list.clear();
	if (tree == null)
		return ;
	for (int i = 0 ; i < tree.getRowCount() ; i++)
	{
		TreePath path = tree.getPathForRow(i) ;
		if (tree.isExpanded(path))
			list.add (path) ;
	}
}
 
Example 11
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JTree getJTree() {
    DebugTreeView treeView1 = getTreeView();
    if (treeView1 != null) {
        JTree tree = treeView1.getTree();
        if (tree != null && tree.getRowCount() > 0) {
            return tree;
        }
    }
    return null;
}
 
Example 12
Source File: AbilityChooserTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	if (!abilityCat.isEditable())
	{
		return;
	}

	Object data = availableTreeViewPanel.getSelectedObject();
	int index = categoryTable.getSelectedRow();
	if (data != null && data instanceof AbilityFacade && index != -1)
	{
		AbilityCategory category = (AbilityCategory) categoryTable.getValueAt(index, 0);
		character.addAbility(category, (AbilityFacade) data);
		availableTreeViewPanel.refilter();
		JTree tree = selectedTreeViewPanel.getTree();
		for (int i = 0; i < tree.getRowCount(); i++)
		{
			TreePath pathForRow = tree.getPathForRow(i);
			if (category.toString().equals(pathForRow.getLastPathComponent().toString()))
			{
				tree.expandRow(i);
			}
		}

	}
}
 
Example 13
Source File: MethodPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void expandAll(JTree tree) {
    int row = 0;
    while (row < tree.getRowCount()) {
        tree.expandRow(row);
        row++;
    }
}
 
Example 14
Source File: CommunityDialog.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private void expandAllNodes(JTree tree, int startingIndex, int rowCount){
    for(int i=startingIndex;i<rowCount;++i){
        tree.expandRow(i);
    }

    if(tree.getRowCount()!=rowCount){
        expandAllNodes(tree, rowCount, tree.getRowCount());
    }
}
 
Example 15
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void firstRow(JTree tree) {
    int rowCount = tree.getRowCount();
    if (rowCount > 0) {
        tree.setSelectionRow(0);
        scrollTreeToSelectedRow(tree);
    }
}
 
Example 16
Source File: CheckNodeListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) {
    int[] rows = tree.getSelectionRows();
    int newRow = rows == null || rows.length == 0 ? 0 : rows[0];
    int maxcount = tree.getRowCount();
    CheckNode node;
    do {
        if (next) {
            newRow++;
            if (newRow >= maxcount) {
                newRow = 0;
            }
        } else {
            newRow--;
            if (newRow < 0) {
                newRow = maxcount - 1;
            }
        }
        TreePath path = tree.getPathForRow(newRow);
        node = (CheckNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
            tree.expandRow(newRow);
            maxcount = tree.getRowCount();
        }
    } while (!node.isLeaf());
    tree.setSelectionRow(newRow);
    tree.scrollRowToVisible(newRow);
}
 
Example 17
Source File: CompanionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void selectCompanion(CompanionFacade compFacade)
{
	TreeTableModel treeTableModel = companionsTable.getTreeTableModel();
	treeTableModel.getRoot();
	TreePath path = null;

	JTree tree = companionsTable.getTree();
	String companionType = compFacade.getCompanionType();
	for (int i = 0; i < tree.getRowCount(); i++)
	{
		TreePath pathForRow = tree.getPathForRow(i);
		Object lastPathComponent = pathForRow.getLastPathComponent();
		if (lastPathComponent.toString().startsWith(companionType))
		{
			tree.expandRow(i);
		}
		else if (lastPathComponent instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode)
		{
			CompanionFacade rowComp =
				(CompanionFacade)
					((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent)
						.getValueAt(0);

			if (rowComp != null && rowComp.getFileRef().get() == compFacade.getFileRef().get()
				&& rowComp.getNameRef().get() == compFacade.getNameRef().get()
				&& rowComp.getRaceRef().get() == compFacade.getRaceRef().get())
			{
				path = pathForRow;
			}
		}
	}
	if (path != null)
	{
		companionsTable.getTree().setSelectionPath(path);
		companionsTable.getTree().scrollPathToVisible(path);
	}
}
 
Example 18
Source File: ObjectViewer.java    From cst with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void expandAllNodes(JTree tree, int startingIndex, int rowCount){
   for(int i=startingIndex;i<rowCount;++i){
      tree.expandRow(i);
   }
   if(tree.getRowCount()!=rowCount){
      expandAllNodes(tree, rowCount, tree.getRowCount());
   }
}
 
Example 19
Source File: ProcessingComponent.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
private void expandAllNodes(@Nonnull JTree tree) {
  for (int i = 0; i < tree.getRowCount(); i++) {
    tree.expandRow(i);
  }
}
 
Example 20
Source File: UIUtil.java    From rest-client with Apache License 2.0 3 votes vote down vote up
/**
* 
* @Title      : expand 
* @Description: Expand tree nodes
* @Param      : @param tree 
* @Return     : void
* @Throws     :
 */
public static void expand(JTree tree)
{
    for (int r = 0; r < tree.getRowCount(); r++)
    {
        tree.expandRow(r);
    }
}