1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package unbbayes.gui.table;
22
23 import java.awt.Color;
24 import java.awt.Component;
25
26 import javax.swing.JTable;
27 import javax.swing.SwingConstants;
28 import javax.swing.UIManager;
29 import javax.swing.table.DefaultTableCellRenderer;
30 import javax.swing.table.JTableHeader;
31
32
33
34
35 public class GroupableTableCellRenderer extends DefaultTableCellRenderer {
36
37
38
39
40 private static final long serialVersionUID = -3785644336203425095L;
41 private Color foregroundColor = Color.WHITE;
42 private Color backgroundColor = Color.BLUE;
43
44 public GroupableTableCellRenderer() {
45
46 }
47
48 public GroupableTableCellRenderer(Color foregroundColor, Color backgroundColor) {
49 this.foregroundColor = foregroundColor;
50 this.backgroundColor = backgroundColor;
51 }
52
53
54
55
56
57
58
59
60
61
62
63 public Component getTableCellRendererComponent(JTable table, Object value,
64 boolean selected, boolean focused, int row, int column) {
65 JTableHeader header = table.getTableHeader();
66 if (header != null) {
67 setForeground(foregroundColor);
68 setBackground(backgroundColor);
69 }
70 setHorizontalAlignment(SwingConstants.CENTER);
71 setText(value != null ? value.toString() : " ");
72 setBorder(UIManager.getBorder("TableHeader.cellBorder"));
73 return this;
74 }
75 }