當前位置: 首頁>>代碼示例>>Java>>正文


Java JTree.getPathForRow方法代碼示例

本文整理匯總了Java中javax.swing.JTree.getPathForRow方法的典型用法代碼示例。如果您正苦於以下問題:Java JTree.getPathForRow方法的具體用法?Java JTree.getPathForRow怎麽用?Java JTree.getPathForRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JTree的用法示例。


在下文中一共展示了JTree.getPathForRow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mouseClicked

import javax.swing.JTree; //導入方法依賴的package包/類
@Override
public void mouseClicked(MouseEvent e) {
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int row = tree.getRowForLocation(e.getX(), e.getY());
    TreePath path = tree.getPathForRow(row);
    
    // if path exists and mouse is clicked exactly once
    if (path != null) {
        FileNode node = (FileNode) path.getLastPathComponent();
        Rectangle chRect = DeletedListRenderer.getCheckBoxRectangle();
        Rectangle rowRect = tree.getPathBounds(path);
        chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
        if (e.getClickCount() == 1 && chRect.contains(p)) {
            boolean isSelected = !(node.isSelected());
            node.setSelected(isSelected);
            ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
            if (row == 0) {
                tree.revalidate();
            }
            tree.repaint();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:RevertDeletedAction.java

示例2: haveCompleteNode

import javax.swing.JTree; //導入方法依賴的package包/類
private boolean haveCompleteNode(JTree tree) {
    int[] selRows = tree.getSelectionRows();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode first = (DefaultMutableTreeNode)
            path.getLastPathComponent();
    int childCount = first.getChildCount();
    // first has children and no children are selected.
    if (childCount > 0 && selRows.length == 1) {
        return false;
    }
    // first may have children.
    for (int i = 1; i < selRows.length; i++) {
        path = tree.getPathForRow(selRows[i]);
        DefaultMutableTreeNode next = (DefaultMutableTreeNode)
                path.getLastPathComponent();
        if (first.isNodeChild(next)) {
            // Found a child of first.
            if (childCount > selRows.length - 1) {
                // Not all children of first are selected.
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:LastNodeLowerHalfDrop.java

示例3: restoreLastExpandedPaths

import javax.swing.JTree; //導入方法依賴的package包/類
/**
 * Expand all the path from the given expandedPaths and the given tree
 * 
 * @param expandedPaths
 *          - the paths to expand
 * @param tree
 *          - the tree on which the paths has to be expanded
 */
public static void restoreLastExpandedPaths(Enumeration<TreePath> expandedPaths, JTree tree) {
	if (expandedPaths != null) {
		List<TreePath> paths = Collections.list(expandedPaths);
		for (int i = 0; i < tree.getRowCount(); i++) {
			TreePath currentPath = tree.getPathForRow(i);
			String currentStringPath = TreeFormatter.getStringPath(currentPath);
			for (TreePath treePath : paths) {
				String stringTreePahr = TreeFormatter.getStringPath(treePath);
				if (currentStringPath.equals(stringTreePahr)) {
					tree.expandRow(i);
				}
			}
		}
	}
}
 
開發者ID:oxygenxml,項目名稱:oxygen-git-plugin,代碼行數:24,代碼來源:TreeFormatter.java

示例4: mousePressed

import javax.swing.JTree; //導入方法依賴的package包/類
@Override
public void mousePressed(MouseEvent event) {
    JTree tree = (JTree) event.getSource();
    int x = event.getX();
    int y = event.getY();

    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if (path == null) {
        return;
    }
    CheckNode node = (CheckNode) path.getLastPathComponent();

    if ( !SwingUtilities.isRightMouseButton(event)) {
        return;
    }
    Object o = node.getUserObject();

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:CheckNodeListener.java

示例5: storeScrollPosition

import javax.swing.JTree; //導入方法依賴的package包/類
/**
 * Store first visible node and its offset. Called when the view is scrolled
 * by the user.
 */
private void storeScrollPosition() {
    JTree tree = getJTree();
    if (tree != null) {
        int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
        int row = tree.getClosestRowForLocation(tree.getRowBounds(0).x + 1,
                scrollTop);
        if (row >= 0) {
            TreePath path = tree.getPathForRow(row);
            if (path != null) {
                int offset = tree.getRowBounds(row).y - scrollTop;
                visibleTreePosition = new VisibleTreePosition(
                        path, offset);
                return;
            }
        } else {
            return;
        }
    }
    visibleTreePosition = null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:DebuggingViewComponent.java

示例6: saveExpansionState

import javax.swing.JTree; //導入方法依賴的package包/類
/**
 * 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) {

	saveSelectionPaths(tree.getSelectionPaths());

	expandedNodes = new HashSet<>();
	expandedRepositories = new HashSet<>();

	for (int i = 0; i < tree.getRowCount(); i++) {
		TreePath path = tree.getPathForRow(i);
		if (tree.isExpanded(path)) {
			Entry entry = (Entry) path.getLastPathComponent();
			String absoluteLocation = entry.getLocation().getAbsoluteLocation();
			if (entry instanceof Repository) {
				expandedRepositories.add(absoluteLocation);
			} else {
				expandedNodes.add(absoluteLocation);
			}

		}
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:28,代碼來源:RepositoryTreeUtil.java

示例7: restoreExpansionState

import javax.swing.JTree; //導入方法依賴的package包/類
/**
 * Expands all repositories and nodes, which have been saved before. Restores selected paths,
 * which have been saved proviously.
 *
 * @param tree
 *            The related tree, containing the path(s)
 */
public void restoreExpansionState(JTree tree) {
	for (int i = 0; i < tree.getRowCount(); i++) {
		TreePath path = tree.getPathForRow(i);
		Object entryObject = path.getLastPathComponent();
		if (entryObject instanceof Entry) {
			Entry entry = (Entry) entryObject;
			String absoluteLocation = entry.getLocation().getAbsoluteLocation();
			if (expandedRepositories.contains(absoluteLocation) || expandedNodes.contains(absoluteLocation)) {
				tree.expandPath(path);
			}
		}
	}

	restoreSelectionPaths(tree);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:23,代碼來源:RepositoryTreeUtil.java

示例8: getTreeCellRendererComponent

import javax.swing.JTree; //導入方法依賴的package包/類
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
		boolean leaf, int row, boolean hasFocus) {
	Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
	((DefaultTreeCellRenderer) renderer).setLeafIcon(null);
	((DefaultTreeCellRenderer) renderer).setIcon(null);
	((DefaultTreeCellRenderer) renderer).setOpenIcon(null);
	((DefaultTreeCellRenderer) renderer).setClosedIcon(null);

	TreePath path = tree.getPathForRow(row);
	if (path != null) {
		if (selectionModel.isPathSelected(path, true)) {
			checkBox.setState(Boolean.TRUE);
		} else {
			checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE);
		}
	}
	removeAll();
	add(checkBox, BorderLayout.WEST);
	add(renderer, BorderLayout.CENTER);
	return this;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:23,代碼來源:ExtendedCheckTreeCellRenderer.java

示例9: getTextForNode

import javax.swing.JTree; //導入方法依賴的package包/類
private String getTextForNode(JTree tree, int row) {
    TreePath treePath = tree.getPathForRow(row);
    if (treePath == null) {
        return row + "";
    }
    StringBuilder sb = new StringBuilder();
    int start = tree.isRootVisible() ? 0 : 1;
    Object[] objs = treePath.getPath();
    for (int i = start; i < objs.length; i++) {
        String pathString;
        if (objs[i].toString() == null) {
            pathString = "";
        } else {
            pathString = escapeSpecialCharacters(getTextForNodeObject(tree, objs[i]));
        }
        sb.append("/" + pathString);
    }
    return sb.toString();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:RTree.java

示例10: haveCompleteNode

import javax.swing.JTree; //導入方法依賴的package包/類
private boolean haveCompleteNode(JTree tree) {
    int[] selRows = tree.getSelectionRows();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode first =
        (DefaultMutableTreeNode)path.getLastPathComponent();
    int childCount = first.getChildCount();
    // first has children and no children are selected.
    if(childCount > 0 && selRows.length == 1)
        return false;
    // first may have children.
    for(int i = 1; i < selRows.length; i++) {
        path = tree.getPathForRow(selRows[i]);
        DefaultMutableTreeNode next =
            (DefaultMutableTreeNode)path.getLastPathComponent();
        if(first.isNodeChild(next)) {
            // Found a child of first.
            if(childCount > selRows.length-1) {
                // Not all children of first are selected.
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:25,代碼來源:TreeTransferHandler.java

示例11: selectNextPrev

import javax.swing.JTree; //導入方法依賴的package包/類
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);
    if (isQuery) {
        CheckNodeListener.findInSource(node);
    } else {
        CheckNodeListener.openDiff(node);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:CheckNodeListener.java

示例12: mouseClicked

import javax.swing.JTree; //導入方法依賴的package包/類
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:CheckListener.java

示例13: selectNextPrev

import javax.swing.JTree; //導入方法依賴的package包/類
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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:CheckNodeListener.java

示例14: format

import javax.swing.JTree; //導入方法依賴的package包/類
@Override
    protected void format(CellContext arg0) {
        //  從CellContext獲取tree中的文字和圖標
        JTree tree = (JTree) arg0.getComponent();
        DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) arg0.getValue();
        Object obj = node.getUserObject();
        if(obj instanceof FieldEntity){
            _label.setText(((FieldEntity) obj).getKey());
            _checkBox.setSelector((FieldEntity) obj);
        }else if(obj instanceof ClassEntity){
            _label.setText(((ClassEntity) obj).getClassName());
            _checkBox.setSelector((ClassEntity) obj);
        }

//        _label.setIcon(arg0.getIcon());

        //  根據selectionModel中的狀態來繪製TristateCheckBox的外觀
        TreePath path = tree.getPathForRow(arg0.getRow());
        if (path != null) {
            if (selectionModel.isPathSelected(path, true)) {
                _checkBox.setState(Boolean.TRUE);
            } else if (selectionModel.isPartiallySelected(path)) {
                _checkBox.setState(null);   //  注意“部分選中”狀態的API
            } else {
                _checkBox.setState(Boolean.FALSE);
            }
        }

        //  使用BorderLayout布局,依次放置TristateCheckBox和JLabel
        rendererComponent.setLayout(new BorderLayout());
        rendererComponent.add(_checkBox);
        rendererComponent.add(_label, BorderLayout.LINE_END);
    }
 
開發者ID:zeng198821,項目名稱:CodeGenerate,代碼行數:34,代碼來源:CheckTreeCellProvider.java

示例15: getText

import javax.swing.JTree; //導入方法依賴的package包/類
@Override public String getText() {
    JTree tree = (JTree) component;
    if (row == -1) {
        return null;
    }
    TreePath rowPath = tree.getPathForRow(row);
    if (rowPath == null) {
        return null;
    }
    Object lastPathComponent = rowPath.getLastPathComponent();
    if (lastPathComponent != null) {
        return getTextForNodeObject(tree, lastPathComponent);
    }
    return null;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:16,代碼來源:RTree.java


注:本文中的javax.swing.JTree.getPathForRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。