当前位置: 首页>>代码示例>>Java>>正文


Java TreeCellRenderer类代码示例

本文整理汇总了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);
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ResultTreeView.java

示例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);
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:27,代码来源:FirstRowCellEditor.java

示例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"));
    }
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:25,代码来源:JTreeTable.java

示例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"));
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:TreeTableCellRenderer.java

示例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);
	}
}
 
开发者ID:cst316,项目名称:spring16project-Modula-2,代码行数:25,代码来源:JTreeTable.java

示例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"));
        }
    }
 
开发者ID:cst316,项目名称:spring16project-Modula-2,代码行数:21,代码来源:TaskTable.java

示例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);
	}
}
 
开发者ID:cst316,项目名称:spring16project-Fortran,代码行数:24,代码来源:JTreeTable.java

示例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"));
	}
}
 
开发者ID:cst316,项目名称:spring16project-Fortran,代码行数:20,代码来源:TaskTable.java

示例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();
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:22,代码来源:BasicTreeUI.java

示例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);
}
 
开发者ID:vilie,项目名称:javify,代码行数:40,代码来源:BasicTreeUI.java

示例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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:TreeTableView.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:TreeExpandableItemsHandler.java

示例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();
     }
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:22,代码来源:BasicTreeUI.java

示例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);
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:40,代码来源:BasicTreeUI.java

示例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"));
    }
}
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:28,代码来源:JXTreeTable.java


注:本文中的javax.swing.tree.TreeCellRenderer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。