01: package com.salmonllc.swing.table;
02:
03: import java.awt.Component;
04:
05: import javax.swing.JTable;
06: import com.salmonllc.swing.SCheckBox;
07: import com.salmonllc.swing.STable;
08:
09: public class CheckBoxCellRenderer extends ExpressionCellRenderer {
10: SCheckBox _box;
11:
12: public CheckBoxCellRenderer(STable t, SCheckBox b) {
13: super (t);
14: _box = new SCheckBox(b.getText());
15: _box.setTrueValue(b.getTrueValue());
16: }
17:
18: public Component getTableCellRendererComponent(JTable table,
19: Object value, boolean isSelected, boolean hasFocus,
20: int row, int column) {
21: boolean selected = false;
22: if (value != null)
23: if (value.toString().equals(_box.getTrueValue()))
24: selected = true;
25: _box.setSelected(selected);
26: if (!isSelected) {
27: _box.setBackground(_tab.getBackground(row));
28: _box.setForeground(_tab.getForeground(row));
29: } else {
30: _box.setBackground(_tab.getSelectionBackground(row));
31: _box.setForeground(_tab.getSelectionForeground(row));
32: }
33: return _box;
34: }
35: }
|