У меня есть JTable
, и я хочу, чтобы результат в таблице имел строки, цвет которых соответствовал конкретному значению атрибута; comp
является null
здесь:Как покрасить строки JTable в соответствии с конкретным значением атрибута
private JNI18NTable _issueIncidentTable = new JNI18NTable(I18N_ID, COLUMNS, "issue.table.") {
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
Component comp = super.prepareRenderer(renderer, row, col);
int RangeIndex = Utilities.rowIndexToRangeIndex(_resultIter, row);
Row theRow = _resultIter.getRowAtRangeIndex(RangeIndex);
System.out.println("the row is" + theRow.getAttribute("Type"));
boolean markRow = theRow != null && theRow.getAttribute("Type").toString().equals("c");
boolean isSelected = isRowSelected(row);
System.out.println("the comp" + comp);
if (markRow) {
comp.setForeground(Color.white);
comp.setBackground(isRowSelected(row) ? Color.red.darker() : Color.red);
} else {
comp.setForeground(isSelected ? getSelectionForeground() : getForeground());
comp.setBackground(isSelected ? getSelectionBackground() : getBackground());
}
return comp;
}
};
Но комп становится нулевым снова и снова, что проблема здесь. –
Я получаю исключение нулевого указателя. –
Пожалуйста, отредактируйте свой вопрос, чтобы включить трассировку [sscce] (http://sscce.org/) и стек, в которой представлена проблема, которую вы описываете. – trashgod