本文整理汇总了Java中javax.swing.tree.TreeCellRenderer.getTreeCellRendererComponent方法的典型用法代码示例。如果您正苦于以下问题:Java TreeCellRenderer.getTreeCellRendererComponent方法的具体用法?Java TreeCellRenderer.getTreeCellRendererComponent怎么用?Java TreeCellRenderer.getTreeCellRendererComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeCellRenderer
的用法示例。
在下文中一共展示了TreeCellRenderer.getTreeCellRendererComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTreeCellRendererComponent
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
boolean isResultRootNode =
(value instanceof TreeNode)
&& (((TreeNode) value).getParent() == null);
// render no icon space an empty icon of a callStackFrame
boolean isCallstackFrame = false;
if (null != value) {
isCallstackFrame = (Visualizer.findNode(value) instanceof CallstackFrameNode);
}
TreeCellRenderer renderer = (isResultRootNode || isCallstackFrame)
? noIconTreeCellRenderer
: defaultTreeCellRenderer;
return renderer.getTreeCellRendererComponent(
tree, value, selected, expanded, leaf, row, hasFocus);
}
示例2: isCellEditable
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
public boolean isCellEditable(final EventObject anEvent) {
if (anEvent instanceof MouseEvent) {
final MouseEvent event = (MouseEvent) anEvent;
final int row = treeTable.rowAtPoint(event.getPoint());
final Rectangle bounds = tree.getRowBounds(row);
int offset = bounds.x;
final Object node = tree.getPathForRow(row).getLastPathComponent();
final boolean leaf = tree.getModel().isLeaf(node);
final boolean expanded = tree.isExpanded(row);
final TreeCellRenderer tcr = tree.getCellRenderer();
final Component treeComponent = tcr.getTreeCellRendererComponent(
tree, node, true, expanded, leaf, row, false);
if (treeComponent instanceof JLabel) {
final JLabel label = (JLabel) treeComponent;
final Icon icon = label.getIcon();
if (icon != null) {
offset += icon.getIconWidth() + label.getIconTextGap();
}
}
if (event.getPoint().x < offset)
return false;
}
return deligate.isCellEditable(anEvent);
}
示例3: paintRow
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
/**
* Paints the renderer part of a row. The receiver should NOT modify
* clipBounds, or insets.
*
* @param g - the graphics configuration
* @param clipBounds -
* @param insets -
* @param bounds - bounds of expand control
* @param path - path to draw control for
* @param row - row to draw control for
* @param isExpanded - is the row expanded
* @param hasBeenExpanded - has the row already been expanded
* @param isLeaf - is the path a leaf
*/
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
Rectangle bounds, TreePath path, int row,
boolean isExpanded, boolean hasBeenExpanded,
boolean isLeaf)
{
boolean selected = tree.isPathSelected(path);
boolean hasIcons = false;
Object node = path.getLastPathComponent();
paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded,
hasBeenExpanded, isLeaf);
TreeCellRenderer dtcr = currentCellRenderer;
boolean focused = false;
if (treeSelectionModel != null)
focused = treeSelectionModel.getLeadSelectionRow() == row
&& tree.isFocusOwner();
Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
isExpanded, isLeaf, row,
focused);
rendererPane.paintComponent(g, c, c.getParent(), bounds);
}
示例4: getCellRendererAndBounds
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
@Override
protected Pair<Component, Rectangle> getCellRendererAndBounds(Integer key) {
int rowIndex = key.intValue();
TreePath path = myComponent.getPathForRow(rowIndex);
if (path == null) return null;
Rectangle bounds = myComponent.getPathBounds(path);
if (bounds == null) return null;
TreeCellRenderer renderer = myComponent.getCellRenderer();
if (renderer == null) return null;
Object node = path.getLastPathComponent();
Component rendererComponent = renderer.getTreeCellRendererComponent(
myComponent,
node,
myComponent.isRowSelected(rowIndex),
myComponent.isExpanded(rowIndex),
myComponent.getModel().isLeaf(node),
rowIndex,
myComponent.hasFocus()
);
return Pair.create(rendererComponent, bounds);
}
示例5: paintRow
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
/**
* Paints the renderer part of a row. The receiver should NOT modify
* clipBounds, or insets.
*
* @param g - the graphics configuration
* @param clipBounds -
* @param insets -
* @param bounds - bounds of expand control
* @param path - path to draw control for
* @param row - row to draw control for
* @param isExpanded - is the row expanded
* @param hasBeenExpanded - has the row already been expanded
* @param isLeaf - is the path a leaf
*/
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
Rectangle bounds, TreePath path, int row,
boolean isExpanded, boolean hasBeenExpanded,
boolean isLeaf)
{
boolean selected = tree.isPathSelected(path);
boolean hasIcons = false;
Object node = path.getLastPathComponent();
paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded,
hasBeenExpanded, isLeaf);
TreeCellRenderer dtcr = currentCellRenderer;
boolean focused = false;
if (treeSelectionModel != null)
focused = treeSelectionModel.getLeadSelectionRow() == row
&& tree.isFocusOwner();
Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
isExpanded, isLeaf, row,
focused);
rendererPane.paintComponent(g, c, c.getParent(), bounds);
}
示例6: getRolloverRenderer
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
@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;
}
示例7: initEditorOffset
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
/**
* @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);
}
示例8: createTreeRenderer
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
/**
* Creates and returns a core default tree cell renderer with tooltip.
* @return
*/
private TreeCellRenderer createTreeRenderer() {
final TreeCellRenderer delegate = new DefaultTreeCellRenderer();
TreeCellRenderer renderer = new TreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component result = delegate.getTreeCellRendererComponent(tree, value,
selected, expanded, leaf, row, hasFocus);
((JComponent) result).setToolTipText(String.valueOf(tree.getPathForRow(row)));
return result;
}
};
return renderer;
}
示例9: getCellRendererAndBounds
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
protected Pair<Component, Rectangle> getCellRendererAndBounds(Integer key) {
int rowIndex = key.intValue();
TreePath path = myComponent.getPathForRow(rowIndex);
if (path == null) return null;
Rectangle bounds = myComponent.getPathBounds(path);
if (bounds == null) return null;
TreeCellRenderer renderer = myComponent.getCellRenderer();
if (renderer == null) return null;
Object node = path.getLastPathComponent();
Component rendererComponent = renderer.getTreeCellRendererComponent(
myComponent,
node,
myComponent.isRowSelected(rowIndex),
myComponent.isExpanded(rowIndex),
myComponent.getModel().isLeaf(node),
rowIndex,
myComponent.hasFocus()
);
return Pair.create(rendererComponent, bounds);
}
示例10: getCellRendererAndBounds
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
@Override
protected Pair<Component, Rectangle> getCellRendererAndBounds(Integer key) {
int rowIndex = key.intValue();
TreePath path = myComponent.getPathForRow(rowIndex);
if (path == null) return null;
Rectangle bounds = myComponent.getPathBounds(path);
if (bounds == null) return null;
TreeCellRenderer renderer = myComponent.getCellRenderer();
if (renderer == null) return null;
Object node = path.getLastPathComponent();
Component rendererComponent = renderer.getTreeCellRendererComponent(
myComponent,
node,
myComponent.isRowSelected(rowIndex),
myComponent.isExpanded(rowIndex),
myComponent.getModel().isLeaf(node),
rowIndex,
myComponent.hasFocus()
);
return Pair.create(rendererComponent, bounds);
}
示例11: createTreeCellRenderer
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
/**
* Creates a cell renderer for the tree view.
*
* @param delegate delegating/original tree renderer.
* @return call renderer for the tree view.
*/
private TreeCellRenderer createTreeCellRenderer(final TreeCellRenderer delegate) {
return new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
return delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
}
};
}
示例12: getTextForNodeObject
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
private String getTextForNodeObject(JTree tree, Object lastPathComponent) {
TreeCellRenderer renderer = tree.getCellRenderer();
if (renderer == null) {
return null;
}
Component c = renderer.getTreeCellRendererComponent(tree, lastPathComponent, false, false, false, 0, false);
if (c != null && c instanceof JLabel) {
return ((JLabel) c).getText();
}
return lastPathComponent.toString();
}
示例13: paintRow
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
private void paintRow(TreeCellRenderer renderer,
DefaultTreeCellRenderer dtcr, SynthContext treeContext,
SynthContext cellContext, Graphics g, Rectangle clipBounds,
Insets insets, Rectangle bounds, Rectangle rowBounds,
TreePath path, int row, boolean isExpanded,
boolean hasBeenExpanded, boolean isLeaf) {
// Don't paint the renderer if editing this row.
boolean selected = tree.isRowSelected(row);
JTree.DropLocation dropLocation = tree.getDropLocation();
boolean isDrop = dropLocation != null
&& dropLocation.getChildIndex() == -1
&& path == dropLocation.getPath();
int state = ENABLED;
if (selected || isDrop) {
state |= SELECTED;
}
if (tree.isFocusOwner() && row == getLeadSelectionRow()) {
state |= FOCUSED;
}
cellContext.setComponentState(state);
if (dtcr != null && (dtcr.getBorderSelectionColor() instanceof
UIResource)) {
dtcr.setBorderSelectionColor(style.getColor(
cellContext, ColorType.FOCUS));
}
SynthLookAndFeel.updateSubregion(cellContext, g, rowBounds);
cellContext.getPainter().paintTreeCellBackground(cellContext, g,
rowBounds.x, rowBounds.y, rowBounds.width,
rowBounds.height);
cellContext.getPainter().paintTreeCellBorder(cellContext, g,
rowBounds.x, rowBounds.y, rowBounds.width,
rowBounds.height);
if (editingComponent != null && editingRow == row) {
return;
}
int leadIndex;
if (tree.hasFocus()) {
leadIndex = getLeadSelectionRow();
}
else {
leadIndex = -1;
}
Component component = renderer.getTreeCellRendererComponent(
tree, path.getLastPathComponent(),
selected, isExpanded, isLeaf, row,
(leadIndex == row));
rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y,
bounds.width, bounds.height, true);
}
示例14: getNodeText
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
/**
* Returns the label text of <code>node</code> in <code>tree</code>.
*/
private String getNodeText(JTree tree, Object node) {
TreeCellRenderer renderer = tree.getCellRenderer();
Component childLabel = renderer.
getTreeCellRendererComponent(tree, node,
false, true, false, 0, false);
return ((JLabel)((JComponent)childLabel).getComponent(0)).getText();
}
示例15: setCellRenderer
import javax.swing.tree.TreeCellRenderer; //导入方法依赖的package包/类
public void setCellRenderer(final TreeCellRenderer x) {
super.setCellRenderer(
new TreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
return x.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, myCellFocused);
}
}
);
}