I would like to remove selected row from JTable
with AbstractTableModel
using a button.
The code below works with DefaultTableModel:
...
MyTableModel mtb;
...
private String[]....
private Object[][]...
...
JTable table = new JTable(mtb)
JButton delete;
...
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(delete))
{
if(table.getSelectedRow()<0)
{
JOptionPane.showMessageDialog(this,"Select row");
}
else
{
mtb.removeRow(table.getSelectedRow());
}
}
}
but it deosn't work with AbstractTablemodel
.
I have a little mess in my code so here is java example from oracle page that can be used:
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…