PageRenderTime 32ms CodeModel.GetById 25ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/renderer/LazyCellRenderer.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 54 lines | 35 code | 7 blank | 12 comment | 1 complexity | febfc4c988fa7b7a79abc5693e0fb702 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.JFormattedTextField;
10import javax.swing.JTable;
11import javax.swing.table.DefaultTableCellRenderer;
12import javax.swing.table.TableColumn;
13
14/**
15 *
16 * @author anti
17 */
18public class LazyCellRenderer extends DefaultTableCellRenderer {
19
20    protected JTable table;
21    private final DefaultTableCellRenderer adaptee = new DefaultTableCellRenderer();
22
23    public LazyCellRenderer(JTable table) {
24        super();
25        this.table = table;
26    }
27
28    @Override
29    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
30            boolean hasFocus, int row, int column) {
31        adaptee.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
32        setForeground(adaptee.getForeground());
33        setBackground(adaptee.getBackground());
34        setBorder(adaptee.getBorder());
35        setFont(adaptee.getFont());
36        setText(adaptee.getText());
37        if (hasFocus) {
38            setBackground(Color.BLUE);
39            setForeground(Color.WHITE);
40        }
41        return this;
42    }
43
44    /**
45     * Set this renderer to the given column + editor
46     * @param column
47     */
48    public void setRendererTo(int column) {
49
50        TableColumn col = table.getColumnModel().getColumn(table.getColumnModel().getColumnIndex(table.getModel().getColumnName(column)));
51        col.setCellEditor(new TableCellEditorForDezimal(new JFormattedTextField()));
52        col.setCellRenderer(this);
53    }
54}