wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable & AbstractTableModel(Delete row problem) " Watch "JTable & AbstractTableModel(Delete row problem) " New topic
Author

JTable & AbstractTableModel(Delete row problem)

Faisal Ahmed
Greenhorn

Joined: Aug 22, 2002
Posts: 8
Hi!!
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 AbstractTableModel.so 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) {
try{
jTable1.setModel(myModel); //jtable is object of JTable and myModel is of Abstract TableModel

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


int row=jTable1.getSelectedRow();
if(row>=0){
model.removeRow();
jTable1.revalidate();
model.fireTableDataChanged();
System.out.println("Rows Delete");
}
}
}
catch(Exception sq){
sq.printStackTrace();
sq.getMessage();
}

}
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.
 
Consider Paul's rocket mass heater.
 
subject: JTable & AbstractTableModel(Delete row problem)
 
Similar Threads
JTable
add an empty row to the Jtable
JTable with inseting and autonumbering problem
JTable
Deleting JTable Row