2011-02-23 3 views
2

셀 데이터에 따라 다른 색을 나타내야하는 JTable 구성 요소의 tablecellrenderer를 구현하고 싶습니다. 나는 이것을 얻었지만, 선택된 셀의 색깔을 바꿀 수는 없다.TableCellRenderer 선택한 셀 문제

public Component getTableCellRendererComponent(JTable table, Object value, 
     boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) 
{ 

    if (isSelected) { 
     this.setBackground((Color)UIManager.get("Table.selectionBackground")); 
     this.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); 
    } else { 
     this.setForeground((Color)UIManager.get("Table.foreground")); 
     this.setBackground((Color)UIManager.get("Table.background")); 
     this.setBorder(BorderFactory.createEmptyBorder()); 
    } 
... 
} 

을했지만 작동하지 않습니다 : 나는이 작업을 수행하려고 내가 셀을 클릭 할 때 JTable의 다른 아무것도 표시되지 않기 때문에 S는 .. 내가 문제를 볼 수 없습니다.

답변

2

나는 다른 색상이 셀 데이터

이 작업을 수행하지 않습니다 게시 된 코드에 따라 표시해야 JTable의 구성 요소의하는 TableCellRenderer를 구현하고자합니다. 기본적으로 모든 코드는 렌더러의 기본 동작을 복제합니다.

Table Row Rendering 접근 방법을 쉽게 구현할 수 있습니다.

0

JLabel을 구성 요소의 기본으로 사용한다고 가정 할 때 opaque를 true로 설정하지 않으면 배경 설정이 적용되지 않습니다. JLabels는 기본적으로 불투명하지 않으므로 배경을 페인트하지 않습니다.

관련 문제