File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable & AbstractTableModel(Delete row problem) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable & AbstractTableModel(Delete row problem) " Watch "JTable & AbstractTableModel(Delete row problem) " New topic

JTable & AbstractTableModel(Delete row problem)

Faisal Ahmed

Joined: Aug 22, 2002
Posts: 8
I have used AbstractTableModel in my JTable.In case of multiple rows, i want to delete rows from interface as well as from database. As removeRow method is absent in DefaultTableModel has been used by casting but CastClassException throws. Here is Partial code(tried in many ways).Plz help me to solve the problem.
void jButtonCancel_actionPerformed(ActionEvent e) {
jTable1.setModel(myModel); //jtable is object of JTable and myModel is of Abstract TableModel

DefaultTableModel model=((DefaultTableModel)jTable1.getModel());

int row=jTable1.getSelectedRow();
System.out.println("Rows Delete");
catch(Exception sq){

Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
Please explain how you create myModel.
AbstractTableModel is an abstract class. Therefore, you can't instantiate it directly.
Do you have your own TableModel class? I have a feeling you would find creating one to be useful. Then you can define the behavior you want custom to your problem (e.g. override deleteRow to also make a call to your database).
If DefaultTableModel does everything you need, then great.
I agree. Here's the link:
subject: JTable & AbstractTableModel(Delete row problem)
It's not a secret anymore!