當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。