• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable & AbstractTableModel(Delete row problem)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}

}
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic