Netbeansでデスクトップアプリケーションを作成しましたが、文字列の値が "処理中"の場合は、特定のセルの色を変更します。私は手動で入力する場合 私はnetbeansでセルの色が変更されない
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;
}
}
を試みたが、私のtableIが
table.getColumnModel().getColumn(7).setCellRenderer(new CustomTableCellRenderer());
I`mは、データベースから値を取得し、ここでのステータスを
for(int i=0; i<arraylist.size(); i++) {
table.setValueAt(status, i, 7);
}
を使用しての使用変更されていないが、String
ですlike:
table.setValueAt("on Process", i, 7);
それは色が変わっても問題ありませんが、そのようにタイプすることはできません。変数から値を設定する必要があります。私はString、Object、no useを試しました! 私はtoString()
を試しましたが、 "+ステータス"を試しました...それは私が割り当てたものを無視しているだけです。 forloopの中で "on process"と入力すると機能しますが、forloopの外側で変数から割り当てることができ、色が変わります。私は混乱している、何をすべきかわからない。 私を助けてください。
返信いただきありがとうございます。しかし、if(obj.toString()。equals( "on process"))を使用すると、NullPointerExceptionがスローされます。 – Jamol
@ user1290988それで 'if(obj!= null && obj.toString()。equals(" on Process "))' –
+1良いキャッチ; more [here](http://stackoverflow.com/a/10150532/230513)。 – trashgod