|
JavaTM Platform Standard Ed. 6 |
|||||||||
전의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
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)
지정된 값을 표시하도록(듯이) 설정된 컴퍼넌트를 돌려줍니다. |
메소드의 상세 |
---|
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
paint
메소드가 불려 가, 셀을 「draw」합니다. 리스트 셀의 사이즈가 고정되어 있지 않기 때문에, 리스트의 치수를 계산할 필요가 있는 경우에는, 이 메소드가 불려 가,getPreferredSize
를 호출할 수 있는 컴퍼넌트를 생성합니다.
list
- 페인트 하고 있는 JListvalue
- list.getModel(). getElementAt(index)에 의해 반환되는 값index
- 셀의 인덱스isSelected
- 지정된 셀이 선택되었을 경우는 truecellHasFocus
- 지정된 셀에 포커스가 있는 경우는 true
JList
,
ListSelectionModel
,
ListModel
|
JavaTM Platform Standard Ed. 6 |
|||||||||
전의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.