本文整理汇总了Java中javax.swing.tree.TreeCellRenderer类的典型用法代码示例。如果您正苦于以下问题:Java TreeCellRenderer类的具体用法?Java TreeCellRenderer怎么用?Java TreeCellRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeCellRenderer类属于javax.swing.tree包,在下文中一共展示了TreeCellRenderer类的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: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI ()
{
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例4: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* UpdateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
final TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr;
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// renderer.setBorderSelectionColor(null);
renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例5: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
((DefaultTreeCellRenderer)this.getCellRenderer()).setLeafIcon(null);
((DefaultTreeCellRenderer)this.getCellRenderer()).setOpenIcon(null);
((DefaultTreeCellRenderer)this.getCellRenderer()).setClosedIcon(null);
}
}
示例6: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
}
}
示例7: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
((DefaultTreeCellRenderer) this.getCellRenderer()).setLeafIcon(null);
((DefaultTreeCellRenderer) this.getCellRenderer()).setOpenIcon(null);
((DefaultTreeCellRenderer) this.getCellRenderer()).setClosedIcon(null);
}
}
示例8: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例9: setCellRenderer
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* Sets the TreeCellRenderer to <code>tcr</code>. This invokes
* <code>updateRenderer</code>.
*
* @param tcr is the new TreeCellRenderer.
*/
protected void setCellRenderer(TreeCellRenderer tcr)
{
// Finish editing before changing the renderer.
completeEditing();
// The renderer is set in updateRenderer.
updateRenderer();
// Refresh the layout if necessary.
if (treeState != null)
{
treeState.invalidateSizes();
updateSize();
}
}
示例10: 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);
}
示例11: TreeTableView
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
public TreeTableView(ListTreeTableModelOnColumns treeTableModel) {
super(treeTableModel);
setRootVisible(false);
setTreeCellRenderer(new TreeCellRenderer() {
private final TreeCellRenderer myBaseRenderer = new HighlightableCellRenderer();
public Component getTreeCellRendererComponent(JTree tree1,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
JComponent result = (JComponent)myBaseRenderer.getTreeCellRendererComponent(tree1, value, selected, expanded, leaf, row, hasFocus);
result.setOpaque(!selected);
return result;
}
});
setSizes();
}
示例12: 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);
}
示例13: setCellRenderer
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* Sets the TreeCellRenderer to <code>tcr</code>. This invokes
* <code>updateRenderer</code>.
*
* @param tcr is the new TreeCellRenderer.
*/
protected void setCellRenderer(TreeCellRenderer tcr)
{
// Finish editing before changing the renderer.
completeEditing();
// The renderer is set in updateRenderer.
updateRenderer();
// Refresh the layout if necessary.
if (treeState != null)
{
treeState.invalidateSizes();
updateSize();
}
}
示例14: 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);
}
示例15: updateUI
import javax.swing.tree.TreeCellRenderer; //导入依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
// TODO JW: need to revisit...
// a) the "real" of a JXTree is always wrapped into a DelegatingRenderer
// consequently the if-block never executes
// b) even if it does it probably (?) should not
// unconditionally overwrite custom selection colors.
// Check for UIResources instead.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is null.
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(
UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(
UIManager.getColor("Table.selectionBackground"));
}
}