本文整理了Java中javax.swing.tree.TreeCellRenderer
类的一些代码示例,展示了TreeCellRenderer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeCellRenderer
类的具体详情如下:
包路径:javax.swing.tree.TreeCellRenderer
类名称:TreeCellRenderer
暂无
代码示例来源:origin: stackoverflow.com
path = path.getParentPath();
Object obj1[] = path1.getPath();
Object obj2[] = path2.getPath();
for(int i = 0; i<obj2.length; i++){
if(obj1[i]!=obj2[i])
Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
TreePath path = tree.getPathForRow(row);
private JTree tree = new JTree();
selectionModel = new CheckTreeSelectionModel(tree.getModel());
代码示例来源:origin: org.swinglabs.swingx/swingx-all
/**
* @param row
* @param isSelected
*/
protected void initEditorOffset(JTable table, int row, int column,
boolean isSelected) {
if (tree == null)
return;
// Rectangle bounds = tree.getRowBounds(row);
// int offset = bounds.x;
Object node = tree.getPathForRow(row).getLastPathComponent();
boolean leaf = tree.getModel().isLeaf(node);
boolean expanded = tree.isExpanded(row);
TreeCellRenderer tcr = tree.getCellRenderer();
Component editorComponent = tcr.getTreeCellRendererComponent(tree, node,
isSelected, expanded, leaf, row, false);
((TreeTableTextField) getComponent()).init(row,
column, table, tree, editorComponent);
}
代码示例来源:origin: stackoverflow.com
JTree tree = new JTree(createTestTreeModel());
panel.add(new JScrollPane(tree), BorderLayout.CENTER);
while (r < tree.getRowCount())
tree.expandRow(r);
r++;
TreeCellRenderer cellRenderer = tree.getCellRenderer();
Component treeCellRendererComponent =
cellRenderer.getTreeCellRendererComponent(
tree, tree.getModel().getRoot(), false, false, false, 1, false);
int rowHeight = treeCellRendererComponent.getPreferredSize().height + 2;
TreePath rootPath = new TreePath(tree.getModel().getRoot());
expandAllRecursively(tree, rootPath);
TreeModel model = tree.getModel();
Object lastPathComponent = treePath.getLastPathComponent();
int childCount = model.getChildCount(lastPathComponent);
if (childCount == 0)
代码示例来源:origin: protegeproject/protege
protected JComponent getRendererComponent() {
return (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree,
tree.getSelectionPath().getLastPathComponent(),
false,
true,
true,
0,
false);
}
代码示例来源:origin: stackoverflow.com
int selRow = tree.getRowForLocation(p.x, p.y);
TreeCellRenderer r = tree.getCellRenderer();
if (selRow != -1 && r != null) {
TreePath path = tree.getPathForRow(selRow);
Object lastPath = path.getLastPathComponent();
Component rComponent = r.getTreeCellRendererComponent(tree, lastPath, tree.isRowSelected(selRow), tree.isExpanded(selRow),
tree.getModel().isLeaf(lastPath), selRow, true);
if (rComponent instanceof JEditorPane) {
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
protected RolloverRenderer getRolloverRenderer(Point location, boolean prepare) {
TreeCellRenderer renderer = component.getCellRenderer();
RolloverRenderer rollover = renderer instanceof RolloverRenderer
? (RolloverRenderer) renderer : null;
if ((rollover != null) && !rollover.isEnabled()) {
rollover = null;
}
if ((rollover != null) && prepare) {
TreePath path = component.getPathForRow(location.y);
Object element = path != null ? path.getLastPathComponent() : null;
renderer.getTreeCellRendererComponent(component, element, false,
false, false,
location.y, false);
}
return rollover;
}
代码示例来源:origin: io.ultreia.java4all.jaxx/jaxx-widgets-extra
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;
}
代码示例来源:origin: javax.help/javahelp
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;
}
}
代码示例来源:origin: org.biomoby/taverna-biomoby
public void paint(Graphics g) {
boolean selected = tree.isRowSelected(row);
Component renderer = tree
.getCellRenderer()
.getTreeCellRendererComponent(
tree,
path.getLastPathComponent(),
tree.isRowSelected(row),
tree.isExpanded(row),
tree.getModel().isLeaf(path.getLastPathComponent()),
row, selected);
c.setFont(tree.getFont());
Rectangle paintBounds = SwingUtilities.convertRectangle(tree,
bounds, this);
SwingUtilities.paintComponent(g, renderer, this, paintBounds);
if (selected)
return;
g.setColor(Color.blue);
((Graphics2D) g).draw(paintBounds);
}
};
代码示例来源:origin: abbot/abbot
Object value = path.getLastPathComponent();
int row = tree.getRowForPath(path);
Component cr = tree.getCellRenderer().
getTreeCellRendererComponent(tree, value, false,
tree.isExpanded(row),
tree.getModel().isLeaf(value),
row, false);
TreePath parentPath = path.getParentPath();
if (parentPath != null) {
Object parent = parentPath.getLastPathComponent();
int idx = tree.getModel().getIndexOfChild(parent, value);
int count = 0;
代码示例来源:origin: org.netbeans.api/org-openide-explorer
/** Configures a tree cell renderer and sets up sizing and the
* backing image from it */
public boolean configure (Object nd, JScrollPane tv, JTree tree, TreePath path, int row) {
boolean sameVn = setLastRendereredObject(nd);
boolean sameComp = setLastRenderedScrollPane (tv);
Component renderer = null;
bg = tree.getBackground();
boolean sel = tree.isSelectionEmpty() ? false :
tree.getSelectionModel().isPathSelected(path);
boolean exp = tree.isExpanded(path);
boolean leaf = !exp && tree.getModel().isLeaf(nd);
boolean lead = path.equals(tree.getSelectionModel().getLeadSelectionPath());
renderer = tree.getCellRenderer().getTreeCellRendererComponent(tree, nd, sel, exp, leaf, row, lead);
if (renderer != null) {
setComponent (renderer);
}
return true;
}
代码示例来源:origin: org.java.net.substance/substance
if (!this.tree.getComponentOrientation().isLeftToRight()
&& LookUtils.IS_JAVA_5) {
bounds.x -= 4;
if (this.tree.hasFocus()) {
TreePath leadPath = this.tree.getLeadSelectionPath();
leadIndex = this.getRowForPath(this.tree, leadPath);
} else {
.getTreeCellRendererComponent(this.tree, path
.getLastPathComponent(), this.tree.isRowSelected(row),
isExpanded, isLeaf, row, (leadIndex == row));
代码示例来源:origin: org.java.net.substance/substance
Insets insets = tree.getInsets();
|| !tree.isOpaque();
.getLastPathComponent());
boolean isExpanded = isLeaf ? false : treeState
.getExpandedState(path);
Component renderer = this.currentCellRenderer
.getTreeCellRendererComponent(this.tree, path
.getLastPathComponent(), this.tree
.isRowSelected(row), isExpanded, isLeaf,
row, tree.hasFocus() ? (tree
.getLeadSelectionRow() == row)
代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui
cellRenderer = treeCellRenderer.getTreeCellRendererComponent(JCheckTree.this, currentTreePath.getLastPathComponent(),
false, isExpanded(row),
getModel().isLeaf(currentTreePath.getLastPathComponent()),
row, false);
cellRendererPersistent = ((TreeCellRendererPersistent) treeCellRenderer).getTreeCellRendererComponentPersistent(JCheckTree.this,
currentTreePath
.getLastPathComponent(),
false,
isExpanded(row),
代码示例来源:origin: net.java.dev.laf-widget/laf-widget
public void dragGestureRecognized(DragGestureEvent dge) {
if (!TreeDragAndDropWidget.this.jcomp.isEnabled())
return;
.getClosestPathForLocation(dge.getDragOrigin().x, dge
.getDragOrigin().y);
if (draggedPath == null)
return;
TreeNode node = (TreeNode) draggedPath.getLastPathComponent();
if ((node instanceof MutableTreeNode) && (node.getParent() != null)
&& (node.getParent() instanceof MutableTreeNode))
TreeDragAndDropWidget.this.jcomp.isExpanded(draggedPath));
TreeDragAndDropWidget.this.rendererProxy.setDraggedNode(node);
.getDragOrigin().y
- dragBounds.y);
Component component = renderer.getTreeCellRendererComponent(
TreeDragAndDropWidget.this.jcomp, node, false,
TreeDragAndDropWidget.this.jcomp.isExpanded(draggedPath),
代码示例来源:origin: robotframework/SwingLibrary
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);
}
代码示例来源:origin: khuxtable/seaglass
boolean hasBeenExpanded, boolean isLeaf) {
boolean selected = tree.isRowSelected(row);
JTree.DropLocation dropLocation = tree.getDropLocation();
boolean isDrop = dropLocation != null && dropLocation.getChildIndex() == -1 && path == dropLocation.getPath();
if (tree.isFocusOwner() && row == getLeadSelectionRow()) {
state |= FOCUSED;
Component component = renderer.getTreeCellRendererComponent(tree, path.getLastPathComponent(), selected, isExpanded, isLeaf, row,
(leadIndex == row));
代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce
protected void paintRow(Graphics g, Rectangle clipBounds,
Insets insets, Rectangle bounds, TreePath path,
int row, boolean isExpanded,
boolean hasBeenExpanded, boolean isLeaf) {
// Don't paint the renderer if editing this row.
if (editingComponent != null && editingRow == row) {
return;
}
Object object = path.getLastPathComponent();
Component component = currentCellRenderer.getTreeCellRendererComponent(tree,
object, tree.isRowSelected(row),
isExpanded, isLeaf, row, false); // hasfocus???
// don't indent the end-tag as far...
if ( object instanceof ElementEndTreeNode) {
int indent = getLeftChildIndent() + getRightChildIndent();
rendererPane.paintComponent(g, component, tree, bounds.x-indent, bounds.y, bounds.width, bounds.height, true);
} else {
rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y, bounds.width, bounds.height, true);
}
}
代码示例来源:origin: icza/scelight
final String tip = super.getToolTipText( event );
if ( tip != null )
return tip;
final TreeNode value = (TreeNode) path.getLastPathComponent();
final Component comp = getCellRenderer().getTreeCellRendererComponent( this, value, isPathSelected( path ), isExpanded( path ), value.isLeaf(),
getRowForPath( path ), false );
if ( comp instanceof JLabel ) {
return path.getLastPathComponent().toString();
代码示例来源:origin: icza/scelight
public Point getToolTipLocation( final MouseEvent event ) {
if ( super.getToolTipText( event ) != null )
return super.getToolTipLocation( event );
location.y -= 2;
final TreeNode value = (TreeNode) path.getLastPathComponent();
final Component comp = getCellRenderer().getTreeCellRendererComponent( this, value, isPathSelected( path ), isExpanded( path ), value.isLeaf(),
getRowForPath( path ), false );
if ( comp instanceof JLabel ) {
内容来源于网络,如有侵权,请联系作者删除!