Make sure you override AbstractTableModel.isCellEditable
method to return true
for the column with the button otherwise the editor will not be triggered. This method by default returns false
.
Also, make sure you override getColumnName()
to return proper name since the sample that you linked tries to find a column with name "Button" to setup the editor.
You may find a Table Button Column implementation by @camickr useful.
This demo model works OK with the editor and the renderer from the linked sample:
public class DemoTableModel extends AbstractTableModel {
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return (columnIndex == 0);
}
@Override
public int getRowCount() {
return 2;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public String getColumnName(int columnIndex) {
switch (columnIndex) {
case 0:
return "Button";
case 1:
return "Value";
}
return null;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return "Button";
case 1:
return "Value";
}
return null;
}
}