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