I got a problem when filtering my JTable. In fact, on my first row I have JComboBoxes in each column. And when I sort which the items of JCombo the first row is also being filtered and disappear.
Here is my Table model:
public static class MyModel extends AbstractTableModel {
private static final long serialVersionUID = -768739845735375515L;
private List<Object[]> data;
private List<String> columnNames;
public MyModel(List<String> columnNames, List<Object[]> data) {
super();
this.columnNames = columnNames;
this.data = data;
}
@Override
public int getRowCount() {
return data.size();
}
@Override
public int getColumnCount() {
return columnNames.size();
}
@Override
public String getColumnName(int column) {
return columnNames.get(column);
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return data.get(rowIndex)[columnIndex];
}
@Override
public boolean isCellEditable(int row, int col) { // Pour modifier uniquement la cellule Statut
if (row == 0) {
return true;
} else {
return false;
}
}
public void setValueAt(Object value, int row, int col) {
data.get(row)[col] = value;
fireTableCellUpdated(row, col);
}
public void removeRow(int row) {
data.remove(row);
}
}
And the combo listener :
private void ComboListener(final JComboBox comboBox){
comboBox.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
String selectedItem = comboBox.getSelectedItem().toString();
sorter.setRowFilter(RowFilter.regexFilter(selectedItem));
}catch(Exception ex){}
}
}
);
}