int editRow = table.getSelectedRow(); ((DefaultTableModel) table.getModel()).removeRow(editRow);异常:
Exception occurred during event dispatching:java.lang.ClassCastException
Exception occurred during event dispatching:java.lang.ClassCastException
是不是你设置了别的model啊,不是用的DefaultTableModel,你搞个断点看看table.getModel())是哪个类呢,不是DefaultTableModel和孩子不行的挖
private static JButton click=new JButton("test");
private static JTable table=new JTable(3,3);
private static int editRow=table.getSelectedRow();
private static JPanel panel=new JPanel();
public static void main(String[] args) {
JFrame main=new JFrame();
main.setSize(300,300);
main.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
click.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
((DefaultTableModel) table.getModel()).removeRow(editRow+1);
}});
panel.add(table);
panel.add(click);
main.getContentPane().add(panel, BorderLayout.CENTER);
main.show();
}
}
楼主,给个例子你,看看有没有帮助!