当前位置: 首页>>代码示例>>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;未经允许,请勿转载。