Hi I have a table with a column as JButton.
i set the renderer as follows
TableColumn col = colModel.getColumn(3);
col.setCellRenderer(new MyRenderer("Del"));
col.setCellEditor(new MultiTradeCellEditor(new JCheckBox()));
The renderer and cellEditor classes are
class MyRenderer extends JButton implements TableCellRenderer{
public MyRenderer(String text){
super(text);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
return this;
}
}
}
CellEditor class
class MultiTradeCellEditor extends DefaultCellEditor{
protected JButton button;
public MultiTradeCellEditor(JCheckBox checkBox) {
super(checkBox);
button = new JButton("Del");
button.setOpaque(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectionList.getList().remove(table.getSelectedRow());
table.repaint();
}
});
}
}
When i remove the row from the table. i do model.remove(table.getSelectedRow()). It removes the row except the JButton. I assume that button is part of a Renderer component so it doesnt get removed. How can i do that ?