0
최근 JTable
에 대한 맞춤 DefaultTableCellRenderer
클래스를 만들 수 있다는 것을 알게되었습니다.JTable setBackground()에서 열과 행 번호 지정
그러나 내 코드는 전체 행만 색칠하지만 조건에 따라 색을 지정하려는 특정 열/셀은 색칠하지 않습니다.
내가 만든 DefaultTableCellRenderer
클래스의 행과 열을 어떻게 지정할 수 있습니까?
그래서 내가 만든 클래스가 있습니다. 그것은 단지 startTime을을의 경우
public class Schedule extends JPanel(){
public Schedule(){
schedulesJtbl.setDefaultRenderer(Object.class, new ScheduleTableCellRenderer());
int startTime = 1230, endTime = 1330;
int jtStartTime = scheduleJtbl.getValueAt(0,1);
int jtEndTime = scheduleJtbl.getValueAt(0,2);
int conflictCheck = 0;
// duplicate startTime and endTime
if((startTime == jtStartTime) && (endTime == jtEndTime)){
conflictCheck++
ScheduleTableCellRenderer.setConflict(conflictCheck);
}
//duplicate startTime
else if(startTime == jtStartTime){
conflictCheck++
ScheduleTableCellRenderer.setConflict(conflictCheck);
}
}
여기가 ScheduleTableCellRenderer에게
public class ScheduleTableCellRenderer extends DefaultTableCellRenderer {
static int conflict = 0;
@Override
public Component getTableCellRendererComponent(
JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int col) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
if (conflict > 0) {
c.setBackground(Color.RED);
} else if (conflict == 0) {
c.setBackground(Color.GREEN);
}
return c;
}
public static void setConflict(int aConflict) {
conflict = aConflict;
}
}
있어 내가 바로 무슨 일처럼 만 열이 아닌 전체 행을 색상 수있는 방법, 중복이 (두 번째 조건으로하는 경우에) 지금 내 JTable에.
난 당신이 날 도울 수 있기를 바랍니다.
감사합니다.
가능한 중복 http://stackoverflow.com/questions/ :
당신은 또한 기본 배경을 재설정해야 17732005/try-to-color-specific-cell-in-jtable-gettablecellrenderercomponent-overide – SomeDude
다음과 같이 열에 조건을 추가해 봤니? if (conflict> 0 && col == 1) –