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...

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top