static void scrollTreeToSelectedRow(final JTree tree) { final int selectedRow = tree.getLeadSelectionRow(); if (selectedRow >=0) { SwingUtilities.invokeLater( new Runnable() { public void run() { tree.scrollRectToVisible(tree.getRowBounds(selectedRow)); } } ); } }
/** Returns the the point at which the popup menu is to be showed. May return null. * @return the point or null */ Point getPositionForPopup () { int i = tree.getLeadSelectionRow(); if (i < 0) return null; Rectangle rect = tree.getRowBounds(i); if (rect == null) return null; Point p = new Point (rect.x, rect.y); // bugfix #36984, convert point by TreeView.this p = SwingUtilities.convertPoint (tree, p, TreeView.this); return p; }
/** Returns the the point at which the popup menu is to be showed. May return null. * @return the point or null */ Point getPositionForPopup () { int i = tree.getLeadSelectionRow(); if (i < 0) return null; Rectangle rect = tree.getRowBounds(i); if (rect == null) return null; Point p = new Point (rect.x, rect.y); // bugfix #36984, convert point by TreeView.this p = SwingUtilities.convertPoint (tree, p, TreeView.this); return p; }
/** Returns the the point at which the popup menu is to be showed. May return null. * @return the point or null */ Point getPositionForPopup() { int i = tree.getLeadSelectionRow(); if (i < 0) { return null; } Rectangle rect = tree.getRowBounds(i); if (rect == null) { return null; } Point p = new Point(rect.x, rect.y); // bugfix #36984, convert point by TreeView.this p = SwingUtilities.convertPoint(tree, p, TreeView.this); return p; }
public Rectangle call() { int row = tree.getRowForLocation(where.x, where.y); if (tree.getLeadSelectionRow() != row || tree.getSelectionCount() != 1) { // NOTE: the row bounds *do not* include the expansion handle return tree.getRowBounds(row); } else { return null; } } });
System.out.println("Min: " + treeSource.getMinSelectionRow()); System.out.println("Max: " + treeSource.getMaxSelectionRow()); System.out.println("Lead: " + treeSource.getLeadSelectionRow()); System.out.println("Row: " + treeSource.getSelectionRows()[0]);
System.out.println("Min: " + treeSource.getMinSelectionRow()); System.out.println("Max: " + treeSource.getMaxSelectionRow()); System.out.println("Lead: " + treeSource.getLeadSelectionRow()); System.out.println("Row: " + treeSource.getSelectionRows()[0]);
System.out.println("Min: " + treeSource.getMinSelectionRow()); System.out.println("Max: " + treeSource.getMaxSelectionRow()); System.out.println("Lead: " + treeSource.getLeadSelectionRow()); System.out.println("Row: " + treeSource.getSelectionRows()[0]);
int selRow = tree.getLeadSelectionRow(); if (selRow >= 0) { Rectangle bounds = tree.getRowBounds(selRow);
private Component getNodeComponent(Object node, TreePath treePath) { int row = tree.getRowForPath(treePath); boolean isLeaf = tree.getModel().isLeaf(node); boolean hasFocus = tree.getLeadSelectionRow() == row; boolean isSelected = tree.isRowSelected(row); boolean isExpanded = tree.isExpanded(row); TreeCellRenderer cellRenderer = tree.getCellRenderer(); return cellRenderer.getTreeCellRendererComponent(tree, node, isSelected, isExpanded, isLeaf, row, hasFocus); }
public Component getRendererComponent() { TreeModel treeModel = tree.getModel(); TreePath treePath = tree.getPathForRow(rowIndex); TreeCellRenderer renderer = tree.getCellRenderer(); boolean isSelected = tree.isPathSelected(treePath); boolean isExpanded = tree.isExpanded(treePath); boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow(); Object item = treePath.getLastPathComponent(); boolean isLeaf = treeModel.isLeaf(item); Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus); component.setFont(tree.getFont()); // FIX Nimbus white foreground on white background if (isSelected) { component.setForeground(UIManager.getColor("Tree.textForeground")); } return component; }
public Component getRendererComponent() { TreeModel treeModel = tree.getModel(); TreePath treePath = tree.getPathForRow(rowIndex); TreeCellRenderer renderer = tree.getCellRenderer(); boolean isSelected = tree.isPathSelected(treePath); boolean isExpanded = tree.isExpanded(treePath); boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow(); Object item = treePath.getLastPathComponent(); boolean isLeaf = treeModel.isLeaf(item); Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus); component.setFont(tree.getFont()); // FIX Nimbus white foreground on white background if (isSelected) { component.setForeground(UIManager.getColor("Tree.textForeground")); } return component; }
private static Component getComponentAt(JTree tree, int x, int y) { try { TreePath path = tree.getPathForLocation(x, y); if (tree.isEditing() && tree.getSelectionPath() == path) { return null; } int row = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(row); boolean isExpanded = tree.isExpanded(path); boolean isLeaf = tree.getModel().isLeaf(value); boolean hasFocus= tree.hasFocus() && tree.getLeadSelectionRow() == row; return tree.getCellRenderer().getTreeCellRendererComponent( tree, value, isSelected, isExpanded, isLeaf, row, hasFocus); } catch (Exception e) { return null; } }
.isRowSelected(row), isExpanded, isLeaf, row, tree.hasFocus() ? (tree .getLeadSelectionRow() == row) : false); Color background = renderer.getBackground();
.isRowSelected(row), isExpanded, isLeaf, row, tree.hasFocus() ? (tree .getLeadSelectionRow() == row) : false); Color background = renderer.getBackground();
public void prepareForTable(Graphics g) { prepareBackgroundColors(); int cm = treeTable.getColumnModel().getColumnMargin(); int rm = treeTable.getRowMargin(); if (cm != 0 || rm != 0) { left = cm/2; right = left + cm%2; top = rm/2; bottom = top + rm%2; } else { left = right = top = bottom = 0; } if (treeTable.getFocusRenderer() != null) { focusRow = focusColumn = -1; } else { focusRow = tree.getLeadSelectionRow(); if (treeTable.isColumnFocusEnabled()) { focusColumn = Integer.MIN_VALUE; } else { focusColumn = treeTable.getLeadSelectionColumn(); } } }