jtable의 특정 셀을 색칠하고 싶습니다. 여기 내 렌더링 클래스입니다. 나는 sysout을 if
블럭에 집어 넣었다. 모든 문자열이 인쇄되지만 셀 색상은 그 중 하나를 제외하고 변경되지 않았습니다. 셀의 값에 따라 jtable의 셀을 색칠하는 방법
Here is the output of my program. Only the first unsuitable value is colored pink.
public class MyRenderer extends DefaultTableCellRenderer {
static double rpmMin, rpmMax, speedMin, speedMax, temperatureMin, temperatureMax, voltageMin, voltageMax;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (!table.isRowSelected(row)) {
if (column == 2 && Double.parseDouble(value.toString()) > rpmMin
&& Double.parseDouble(value.toString()) < rpmMax) {
c.setBackground(Color.PINK);
}
if(column == 3 && Double.parseDouble(value.toString()) > speedMin
&& Double.parseDouble(value.toString()) < speedMax){
c.setBackground(Color.PINK);
}
if (column == 4 && Double.parseDouble(value.toString()) > temperatureMin
&& Double.parseDouble(value.toString()) < temperatureMax) {
c.setBackground(Color.PINK);
}
if(column == 5 && Double.parseDouble(value.toString()) > voltageMin
&& Double.parseDouble(value.toString()) < voltageMax){
c.setBackground(Color.PINK);
}
else {
c.setBackground(Color.GREEN);
}
}
return c;
}
}
I는 적절한 출력을 표시 할 엑셀을 준비했다.
Here is the picture that I expected to see as output of this program
왜 작동하지 않았는지 알 수 없습니다. 누군가 제게 설명해 주시겠습니까? 고마워요 :)
1) 더 나은 도움을 받으려면 [MCVE] 또는 [짧은, 자체 포함, 올바른 예] (http://www.sscce.org/)를 게시하십시오. 2) 더 이상 고칠 수없는 문제에 대해서는 [코드 블록의 걸쇠 대괄호 탐지/수정] (http://meta.stackexchange.com/q/251795/155831)을 참조하십시오. –