0
JTree 파일에 대한 트리 렌더러를 작성했으며 트리를 처음 만들 때 배경색을 설정할 수 있지만 선택 영역을 강조 표시하지는 않습니다. 추가JTree TreeCellRenderer 강조 표시 선택 없음
super.getTreeCellRendererComponent
private class CustomTreeCellRenderer extends DefaultTreeCellRenderer{
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
if(value instanceof DefaultMutableTreeNode){
setText(FileSystemView.getFileSystemView().getSystemDisplayName((File) ((DefaultMutableTreeNode) value).getUserObject()));
setIcon(FileSystemView.getFileSystemView().getSystemIcon((File) ((DefaultMutableTreeNode) value).getUserObject()));
}
super.setBackgroundSelectionColor(Color.BLUE);
if(selected){
super.setBackground(Color.gray);
setForeground(getTextSelectionColor());
}else{
super.setBackground(Color.CYAN);
setForeground(getTextNonSelectionColor());
}
this.setOpaque(true);
return this;
}
}
문제를 해결했다.