1. /*
  2. * @(#)ListCellRenderer.java 1.16 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import java.awt.Component;
  9. /**
  10. * Identifies components that can be used as "rubber stamps" to paint
  11. * the cells in a JList. For example, to use a JLabel as a
  12. * ListCellRenderer, you would write something like this:
  13. * <pre>
  14. * class MyCellRenderer extends JLabel implements ListCellRenderer {
  15. * public MyCellRenderer() {
  16. * setOpaque(true);
  17. * }
  18. * public Component getListCellRendererComponent(
  19. * JList list,
  20. * Object value,
  21. * int index,
  22. * boolean isSelected,
  23. * boolean cellHasFocus)
  24. * {
  25. * setText(value.toString());
  26. * setBackground(isSelected ? Color.red : Color.white);
  27. * setForeground(isSelected ? Color.white : Color.black);
  28. * return this;
  29. * }
  30. * }
  31. * </pre>
  32. *
  33. * @see JList
  34. * @see DefaultListCellRenderer
  35. *
  36. * @version 1.16 01/23/03
  37. * @author Hans Muller
  38. */
  39. public interface ListCellRenderer
  40. {
  41. /**
  42. * Return a component that has been configured to display the specified
  43. * value. That component's <code>paint</code> method is then called to
  44. * "render" the cell. If it is necessary to compute the dimensions
  45. * of a list because the list cells do not have a fixed size, this method
  46. * is called to generate a component on which <code>getPreferredSize</code>
  47. * can be invoked.
  48. *
  49. * @param list The JList we're painting.
  50. * @param value The value returned by list.getModel().getElementAt(index).
  51. * @param index The cells index.
  52. * @param isSelected True if the specified cell was selected.
  53. * @param cellHasFocus True if the specified cell has the focus.
  54. * @return A component whose paint() method will render the specified value.
  55. *
  56. * @see JList
  57. * @see ListSelectionModel
  58. * @see ListModel
  59. */
  60. Component getListCellRendererComponent(
  61. JList list,
  62. Object value,
  63. int index,
  64. boolean isSelected,
  65. boolean cellHasFocus);
  66. }