< prev index next >

src/java.desktop/share/classes/javax/swing/tree/TreeCellRenderer.java

Print this page




  25 package javax.swing.tree;
  26 
  27 import java.awt.Component;
  28 import javax.swing.JTree;
  29 
  30 /**
  31  * Defines the requirements for an object that displays a tree node.
  32  * See <a
  33  href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>
  34  * in <em>The Java Tutorial</em>
  35  * for an example of implementing a tree cell renderer
  36  * that displays custom icons.
  37  *
  38  * @author Rob Davis
  39  * @author Ray Ryan
  40  * @author Scott Violet
  41  */
  42 public interface TreeCellRenderer {
  43 
  44     /**
  45      * Sets the value of the current tree cell to <code>value</code>.
  46      * If <code>selected</code> is true, the cell will be drawn as if
  47      * selected. If <code>expanded</code> is true the node is currently
  48      * expanded and if <code>leaf</code> is true the node represents a
  49      * leaf and if <code>hasFocus</code> is true the node currently has
  50      * focus. <code>tree</code> is the <code>JTree</code> the receiver is being
  51      * configured for.  Returns the <code>Component</code> that the renderer
  52      * uses to draw the value.
  53      * <p>
  54      * The <code>TreeCellRenderer</code> is also responsible for rendering the
  55      * the cell representing the tree's current DnD drop location if
  56      * it has one. If this renderer cares about rendering
  57      * the DnD drop location, it should query the tree directly to
  58      * see if the given row represents the drop location:
  59      * <pre>
  60      *     JTree.DropLocation dropLocation = tree.getDropLocation();
  61      *     if (dropLocation != null
  62      *             &amp;&amp; dropLocation.getChildIndex() == -1
  63      *             &amp;&amp; tree.getRowForPath(dropLocation.getPath()) == row) {
  64      *
  65      *         // this row represents the current drop location
  66      *         // so render it specially, perhaps with a different color
  67      *     }
  68      * </pre>
  69      *
  70      * @param tree      the receiver is being configured for
  71      * @param value     the value to render
  72      * @param selected  whether node is selected
  73      * @param expanded  whether node is expanded
  74      * @param leaf      whether node is a lead node


  25 package javax.swing.tree;
  26 
  27 import java.awt.Component;
  28 import javax.swing.JTree;
  29 
  30 /**
  31  * Defines the requirements for an object that displays a tree node.
  32  * See <a
  33  href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>
  34  * in <em>The Java Tutorial</em>
  35  * for an example of implementing a tree cell renderer
  36  * that displays custom icons.
  37  *
  38  * @author Rob Davis
  39  * @author Ray Ryan
  40  * @author Scott Violet
  41  */
  42 public interface TreeCellRenderer {
  43 
  44     /**
  45      * Sets the value of the current tree cell to {@code value}.
  46      * If {@code selected} is true, the cell will be drawn as if
  47      * selected. If {@code expanded} is true the node is currently
  48      * expanded and if {@code leaf} is true the node represents a
  49      * leaf and if {@code hasFocus} is true the node currently has
  50      * focus. {@code tree} is the {@code JTree} the receiver is being
  51      * configured for.  Returns the {@code Component} that the renderer
  52      * uses to draw the value.
  53      * <p>
  54      * The {@code TreeCellRenderer} is also responsible for rendering the
  55      * the cell representing the tree's current DnD drop location if
  56      * it has one. If this renderer cares about rendering
  57      * the DnD drop location, it should query the tree directly to
  58      * see if the given row represents the drop location:
  59      * <pre>
  60      *     JTree.DropLocation dropLocation = tree.getDropLocation();
  61      *     if (dropLocation != null
  62      *             &amp;&amp; dropLocation.getChildIndex() == -1
  63      *             &amp;&amp; tree.getRowForPath(dropLocation.getPath()) == row) {
  64      *
  65      *         // this row represents the current drop location
  66      *         // so render it specially, perhaps with a different color
  67      *     }
  68      * </pre>
  69      *
  70      * @param tree      the receiver is being configured for
  71      * @param value     the value to render
  72      * @param selected  whether node is selected
  73      * @param expanded  whether node is expanded
  74      * @param leaf      whether node is a lead node
< prev index next >