views:

38

answers:

0

This is my JTable Renderer class. After I applied this to my jTable, when i click on the row it only highlight the cell instead of whole row. I tried to setRowSelection(true) and setCellSelection(false) but still no use.

class jTableRenderer extends DefaultTableCellRenderer
{
    public Component getTableCellRendererComponent(JTable table,
            Object value, boolean selected, boolean focused, int row,
            int column) {
        super.getTableCellRendererComponent(table, value, selected,
                        focused, row, column);
        String s = table.getModel().getValueAt(row, 6).toString();
        if (s.equals("W")) {
            setBackground(Color.blue);
        } else {
            setBackground(Color.green);
        }           
       return this;
    }
}


private JTable getJTable() {
    String[] colName = { "Date", "Description", "Category", "In", "Out"};
    if (jTable == null) {
        jTable = new JTable() {
            public boolean isCellEditable(int nRow, int nCol) {
                return false;
            }
        };
    }
    DefaultTableModel contactTableModel = (DefaultTableModel) jTable
            .getModel();
    contactTableModel.setColumnIdentifiers(colName);
    jTable.setDefaultRenderer(jTable.getColumnClass(0),
            new jTableRenderer());
    return jTable;
}