Question

i´m trying to put a checkbox in a column in my table...but i shows de boolean value, when i click over the cell, it shows the checkbox and sooner show the boolean value...

    public class Tabela {

    private JTable tabela;
    private JCheckBox checkbox;

    public Tabela(Object[][] linhas, String[] nomeColunas) {    
        this.tabela = new JTable();
        this.tabela.setModel(new DefaultTableModel(linhas, nomeColunas));
        this.checkbox = new JCheckBox();
        this.tabela.setFillsViewportHeight(true);
        this.tabela.getColumn("Selecione").setCellEditor(
              new DefaultCellEditor(checkbox));    
    }

    public JTable getTabela() {    
        return tabela;    
    }    
}

So what´s wrong with my code?

I create seppareted my form, table and panel...

Was it helpful?

Solution

You must override getColumnClass(...) and return Boolean.class for the column that should display the checkboxes. The data model will need to hold Boolean objects for that column as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top