Rendering JList Elements : JList Renderer « Swing « Java Tutorial

  1. Every JList has an installed cell renderer that draws every cell.
  2. A class that implements the ListCellRenderer interface provides this renderer.
  3. When it's time to draw each cell, the interface's sole method is called.
  4. The JList has an installed renderer.
  5. The returned renderer provides the specific rendering for that one cell of the JList.
  6. The JList uses the rendering to draw the element, and then gets the next renderer.
public interface ListCellRenderer {
  public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus);

14.41.JList Renderer
14.41.1.Rendering JList Elements
14.41.2.Install List cell rendererInstall List cell renderer
14.41.3.Add your own ListCellRendererAdd your own ListCellRenderer
14.41.4.Creating a Complex ListCellRenderer: font, icon and colorCreating a Complex ListCellRenderer: font, icon and color
14.41.5.The items can be arbitrary objects. The toString() method of the objects is displayed in the list component.
14.41.6.Setting the Dimensions of an Item in a JList Component
14.41.7.Set the item dimensions using a sample value
14.41.8.Change the layout orientation so that its items are displayed top-to-bottom and left-to-right.