PageRenderTime 41ms CodeModel.GetById 34ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/renderer/TableCellRendererForDatabaseObjects.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 39 lines | 27 code | 4 blank | 8 comment | 2 complexity | cf66cb3b878544406b4d20722f4a925f MD5 | raw file
 1/*
 2 * To change this template, choose Tools | Templates
 3 * and open the template in the editor.
 4 */
 5package mpv5.utils.renderer;
 6
 7import java.awt.Color;
 8import java.awt.Component;
 9import javax.swing.JTable;
10import javax.swing.table.DefaultTableCellRenderer;
11import mpv5.db.common.DatabaseObject;
12
13/**
14 *
15 * @author anti
16 */
17public class TableCellRendererForDatabaseObjects extends DefaultTableCellRenderer {
18
19    private DefaultTableCellRenderer adaptee = new DefaultTableCellRenderer();
20
21    @Override
22    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
23            boolean hasFocus, int row, int column) {
24        adaptee.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
25        setForeground(adaptee.getForeground());
26        setBackground(adaptee.getBackground());
27        setBorder(adaptee.getBorder());
28        setFont(adaptee.getFont());
29        setText(adaptee.getText());
30        if (hasFocus) {
31            setBackground(Color.BLUE);
32            setForeground(Color.WHITE);
33        }
34        if (!isSelected) {
35            setBackground(((DatabaseObject) table.getModel().getValueAt(table.convertRowIndexToModel(row), 0)).getColor());
36        }
37        return this;
38    }
39}