JavaTM Platform
Standard Ed. 6

javax.swing
인터페이스 ListCellRenderer

기존의 구현 클래스의 일람:
BasicComboBoxRenderer , BasicComboBoxRenderer.UIResource , DefaultListCellRenderer , DefaultListCellRenderer.UIResource , MetalFileChooserUI.FileRenderer , MetalFileChooserUI.FilterComboBoxRenderer


public interface ListCellRenderer

JList 내의 셀을 페인트 하는 「고무표」로서 사용할 수 있는 컴퍼넌트를 식별합니다. 예를 들어, JLabel 를 ListCellRenderer 로서 사용하려면 , 다음과 같이 씁니다.

 class MyCellRenderer extends JLabel implements ListCellRenderer {
     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;
     }
 }
 

관련 항목:
JList , DefaultListCellRenderer

메소드의 개요
 Component getListCellRendererComponent (JList  list, Object  value, int index, boolean isSelected, boolean cellHasFocus)
          지정된 값을 표시하도록(듯이) 설정된 컴퍼넌트를 돌려줍니다.
 

메소드의 상세

getListCellRendererComponent

Component  getListCellRendererComponent(JList  list,
                                       Object  value,
                                       int index,
                                       boolean isSelected,
                                       boolean cellHasFocus)
지정된 값을 표시하도록(듯이) 설정된 컴퍼넌트를 돌려줍니다. 다음에, 그 컴퍼넌트의 paint 메소드가 불려 가, 셀을 「draw」합니다. 리스트 셀의 사이즈가 고정되어 있지 않기 때문에, 리스트의 치수를 계산할 필요가 있는 경우에는, 이 메소드가 불려 가,getPreferredSize 를 호출할 수 있는 컴퍼넌트를 생성합니다.

파라미터:
list - 페인트 하고 있는 JList
value - list.getModel(). getElementAt(index)에 의해 반환되는 값
index - 셀의 인덱스
isSelected - 지정된 셀이 선택되었을 경우는 true
cellHasFocus - 지정된 셀에 포커스가 있는 경우는 true
반환값:
지정된 값을 draw 하는 paint() 메소드가 있는 컴퍼넌트
관련 항목:
JList , ListSelectionModel , ListModel

JavaTM Platform
Standard Ed. 6

버그의 보고와 기능의 요청
한층 더 자세한 API 레퍼런스 및 개발자 문서에 대해서는,Java SE 개발자용 문서를 참조해 주세요. 개발자전용의 상세한 해설, 개념의 개요, 용어의 정의, 버그의 회피책, 및 코드 실례가 포함되어 있습니다.

Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.