-  
       
- 参数类型
 -  
         
E- 此呈现器可用于的值的类型 
- 所有已知实现类:
 -  
         
BasicComboBoxRenderer,BasicComboBoxRenderer.UIResource,DefaultListCellRenderer,DefaultListCellRenderer.UIResource,MetalFileChooserUI.FileRenderer,MetalFileChooserUI.FilterComboBoxRenderer 
public interface ListCellRenderer<E>标识可用作“橡皮图章”的组件,以在JList中绘制单元格。 例如,要将JLabel用作ListCellRenderer,您可以编写如下内容:class MyCellRenderer extends JLabel implements ListCellRenderer<Object> { public MyCellRenderer() { setOpaque(true); } public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString()); Color background; Color foreground; // check if this cell represents the current DnD drop location JList.DropLocation dropLocation = list.getDropLocation(); if (dropLocation != null && !dropLocation.isInsert() && dropLocation.getIndex() == index) { background = Color.BLUE; foreground = Color.WHITE; // check if this cell is selected } else if (isSelected) { background = Color.RED; foreground = Color.WHITE; // unselected, and not the DnD drop location } else { background = Color.WHITE; foreground = Color.BLACK; }; setBackground(background); setForeground(foreground); return this; } }- 从以下版本开始:
 - 1.2
 - 另请参见:
 -  
         
JList,DefaultListCellRenderer 
 
-  
        
       
-  
             
方法详细信息
-  
getListCellRendererComponent
Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus)
返回已配置为显示指定值的组件。 然后调用该组件的paint方法来“渲染”该单元格。 如果由于列表单元格没有固定大小而需要计算列表的维度,则调用此方法以生成可在其上调用getPreferredSize的组件。- 参数
 -  
              
list- 我们正在绘制的JList。 -  
              
value- list.getModel()。getElementAt(index)返回的值。 -  
              
index- 细胞索引。 -  
              
isSelected- 如果选择了指定的单元格,isSelectedTrue。 -  
              
cellHasFocus- 如果指定的单元格具有焦点,cellHasFocusTrue。 - 结果
 - paint()方法将呈现指定值的组件。
 - 另请参见:
 -  
              
JList,ListSelectionModel,ListModel 
 
 -  
 
 -