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