Netbeans を使用してデスクトップ アプリケーションを作成しました。「on Process」の文字列値がある場合、特定のセルの色を変更したいと考えています。私は試した
class CustomTableCellRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent (JTable table, Object obj,
boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(
table, obj, isSelected, hasFocus, row, column);
if (obj=="on Process") {
cell.setBackground(Color.green);
}
return cell;
}
}
しかし、使用したテーブルは変更されていません
table.getColumnModel().getColumn(7).setCellRenderer(new CustomTableCellRenderer());
データベースから値を取得して使用しています
for(int i=0; i<arraylist.size(); i++) {
table.setValueAt(status, i, 7);
}
ここで status はString
、次のように手動で入力した場合です。
table.setValueAt("on Process", i, 7);
色が変わります。問題ありませんが、そのように入力することはできません。変数から値を設定する必要があります。私は文字列、オブジェクトを試しましたが、役に立ちません! を試しtoString()
ました、""+status を試しました...割り当てたものを無視しているだけです。forloop内で「on Process」と入力すると機能しますが、forloop外では変数から割り当てることができ、色が変わります。どうすればいいのかわからず、困っています。私を助けてください。