當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeCellRenderer.getTreeCellRendererComponent方法代碼示例

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

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:TreeExpandableItemsHandler.java

示例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);
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:40,代碼來源:BasicTreeUI.java

示例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;
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:18,代碼來源:TreeRolloverController.java

示例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);
    }
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:21,代碼來源:TreeTableCellEditor.java

示例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;
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:21,代碼來源:JXTreeTableVisualCheck.java

示例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);
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:TreeExpandableItemsHandler.java

示例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);
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:26,代碼來源:TreeExpandableItemsHandler.java

示例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);
        }
    };
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:DocumentViewPanel.java

示例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();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:12,代碼來源:JTreeJavaElement.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:59,代碼來源:SynthTreeUI.java

示例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();
}
 
開發者ID:valsr,項目名稱:SweetHome3D,代碼行數:11,代碼來源:CatalogTreeTest.java

示例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);
        }
      }
  );
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:TreeTableTree.java


注:本文中的javax.swing.tree.TreeCellRenderer.getTreeCellRendererComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。