FileDocCategorySizeDatePackage
IconAndTipRenderer.javaAPI DocExample1991Thu Oct 24 20:14:26 BST 2002None

IconAndTipRenderer

public class IconAndTipRenderer extends JLabel implements TreeCellRenderer

Fields Summary
Color
backColor
Icon
openIcon
Icon
closedIcon
Icon
leafIcon
String
tipText
Constructors Summary
public IconAndTipRenderer(Icon open, Icon closed, Icon leaf)


         
    openIcon = open;
    closedIcon = closed;
    leafIcon = leaf;
    setBackground(backColor);
    setForeground(Color.black);
  
Methods Summary
public java.lang.StringgetToolTipText()

    return tipText;
  
public java.awt.ComponentgetTreeCellRendererComponent(javax.swing.JTree tree, java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)

    setText(value.toString());
    if (selected) {
      setOpaque(true);
    }
    else {
      setOpaque(false);
    }

    // Try to find an IconAndTipCarrier version of the current node.
    IconAndTipCarrier itc = null;
    if (value instanceof DefaultMutableTreeNode) {
      Object uo = ((DefaultMutableTreeNode)value).getUserObject();
      if (uo instanceof IconAndTipCarrier) {
        itc = (IconAndTipCarrier)uo;
      }
    }
    else if (value instanceof IconAndTipCarrier) {
      itc = (IconAndTipCarrier)value;
    }
    if ((itc != null) && (itc.getIcon() != null)) {
      // Great! Use itc's values to customize this label
      setIcon(itc.getIcon());
      tipText = itc.getToolTipText();
    }
    else {
      // Hmmm, nothing available, so rely on the defaults.
      tipText = " ";
      if (expanded) {
        setIcon(openIcon);
      }
      else if (leaf) {
        setIcon(leafIcon);
      }
      else {
        setIcon(closedIcon);
      }
    }
    return this;