本文整理匯總了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);
}
}
);
}