- 论坛徽章:
- 0
|
JTable/TableCellRenderer
The problem is:
...
class CrossTableCellRenderer extends DefaultTableCellRenderer {
private Color c1 = new Color(160, 160, 255);
private Color c2 = new Color(255, 160, 160);
private Color c3 = new Color(255, 255, 255);
private int row_;
private int col_;
public Component getTableCellRendererComponent(JTable t, Object v, boolean s, boolean f, int r, int c) {
Component cell = super.getTableCellRendererComponent(t, v, s, f, r, c);
if (s || f) {
row_ = r;
col_ = c;
cell.setBackground(c2);
}
else {
if (r == row_ || c == col_)
cell.setBackground(c1);
else
cell.setBackground(c3);
}
return cell;
}
}
...
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("global pivoting")) {
mat.set_global(); // do some operation
table.repaint();
}
...
If I click the "global pivoting" button, and the JTable table will be drawed, but in
the renderer the variables s (for selected) and f (for focus) do not change.
Could you give some advices in details.
Thanks a lot. |
|