else
охватывает только последние if
.
Также не уверен, хотите ли вы установить передний или задний план в блоке else
.
Я предполагаю, что вы хотитеelse
s вроде:
if (row >= 0 && row <4) {
parent.setBackground(Color.BLUE);
parent.setForeground(Color.WHITE);
} else if (row >= 4 && row <6) {
parent.setBackground(Color.orange);
parent.setForeground(Color.WHITE);
} else if (row >= 17 && row <19) {
parent.setBackground(Color.RED);
parent.setForeground(Color.WHITE);
} else {
// setForeground?? - currently whatever was set last time through.
parent.setBackground(Color.white);
}
Также шрифт обычно оставляют на то, что было установлено в прошлый раз.
Возможно, лучше написать что-то вроде:
import static java.awt.Color. *;
Component component = super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column
);
// Here we just set a certain cell to bold
component.setFont(parent.getFont().deriveFont(
value.equals(nombre) ? Font.BOLD: Font.PLAIN
));
final Color fg;
final Color bg;
if (0 <= row && row < 4) {
fg = WHITE; bg = BLUE;
} else if (row <= 4 && row < 6) {
fg = WHITE; bg = ORANGE;
} else if (17 <= row && row < 19) {
fg = WHITE; bg = RED;
} else {
fg = BLACK; bg = WHITE;
}
component.setForeground(fg);
component.setBackground(bg);
(Обратите внимание, this
работает также component
, но вам необходимо его настроить.)