1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.gui;
19
20 import java.awt.Color;
21 import java.awt.Component;
22 import java.awt.Font;
23
24 import javax.swing.JTable;
25 import javax.swing.table.DefaultTableCellRenderer;
26
27 public class SelectableTableModelRenderer extends DefaultTableCellRenderer {
28
29 private static final long serialVersionUID = 5386816137675796795L;
30
31 @Override
32 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
33 DefaultTableCellRenderer r = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
34 SelectableTableModel model = (SelectableTableModel) table.getModel();
35 r.setForeground(Color.BLACK);
36 if (model.isSelected(row)) {
37 r.setFont(r.getFont().deriveFont(Font.BOLD));
38 r.setBackground(Color.YELLOW);
39 r.setOpaque(true);
40 } else {
41 r.setFont(r.getFont().deriveFont(Font.PLAIN));
42 r.setBackground(Color.WHITE);
43 r.setOpaque(false);
44 }
45 return r;
46 }
47 }