jtableの特定のセルを色付けしたいと思います。ここに私のレンダークラスがあります。 sysoutをif
ブロックに置く。すべての文字列が印刷されますが、セルの色はそれらの1つを除いて変更されませんでした。セルの値に応じてjtableのセルを色付けする方法
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;
}
}
Here is the output of my program. Only the first unsuitable value is colored pink.
私は適切な出力を表示するために、Excelを準備。 Here is the picture that I expected to see as output of this program
なぜ動作しないのか分かりません。誰かが私にそれを説明できますか?ありがとうたくさん:)
1)すぐに役立つようにするには、[MCVE]または[Short、Self Contained、Correct Example](http://www.sscce.org/)を投稿してください。 2)「コードブロックの括弧の検出/修正」(http://meta.stackexchange.com/q/251795/155831)を参照して、修正できなくなった問題を解決してください。 –