Thursday, 8 August 2013

Make a JCheckBox in a JTable editable

Make a JCheckBox in a JTable editable

I need some help with my JTable. I am writing a program, wich extracts
data from a database into a JTable. The first column should be a editable
JCheckBox so I am able to work with the checked (true or false) rows and
the data.
I am using a AbstractTableModel(with class extends AbstractTableModel) and
override these five methods:
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0;
}
@Override
public Class<?> getColumnClass(int col) {
if (col == 0) {
return Boolean.class;
}
return super.getColumnClass(col);
}
@Override
public int getColumnCount() {
return header.length;
}
@Override
public int getRowCount() {
return data.length;
}
@Override
public Object getValueAt(int row, int col) {
return data[row][col];
}
To display the JTable I use:
JTable table = new JTable();
JScrollPane scrollpane = new JScrollPane();
. . .
table = new JTable(data, header);
table.setModel(this);
scrollpane = new JScrollPane(table);
I read the data with a for loop into the data array. The header array I
defined. Basically I need the checked rows to send a mail with the right
data in it.
Thank you for help!

No comments:

Post a Comment