TreeCellRenderer

TreeCellRenderer (트리 노드 표시)

TreeCellRenderer은 트리 노드를 표시하는 객체에 대한 요구사항을 정의하는 인터페이스예요. 사용자 지정 아이콘을 표시하는 트리 셀 렌더러를 구현하는 예시는 The Java Tutorial의 "How to Use Trees"에서 확인할 수 있어요. 알려진 구현 클래스는 DefaultTreeCellRenderer이에요.

출처: Java API Reference

본문

메서드

  • Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) — 현재 트리 셀의 값을 value로 설정해요. selectedtrue이면 셀을 선택된 것처럼 그려요. expandedtrue이면 노드가 현재 확장된 상태이고, leaftrue이면 노드가 리프를 나타내고, hasFocustrue이면 노드가 현재 포커스를 가져요. tree는 수신자가 구성되는 JTree예요.

렌더러가 값을 그리는 데 사용하는 Component를 반환해요. TreeCellRenderer은 트리에서 현재 DnD 드롭 위치를 나타내는 셀을 렌더링할 책임도 있어요. 드롭 위치 렌더링에 관심이 있다면 트리에 직접 질의해 주어진 행이 드롭 위치를 나타내는지 확인해야 해요:

JTree.DropLocation dropLocation = tree.getDropLocation();
if (dropLocation != null && dropLocation.getChildIndex() == -1
    && tree.getRowForPath(dropLocation.getPath()) == row) {
    // this row represents the current drop location
    // so render it specially, perhaps with a different color
}

더 알아보기 (Learn more)

Java 공식 API