Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jTable cannot find symbol method delRow(int)

 
Albert Robert
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DefaultTableModel jTable1_d_t_model = (DefaultTableModel) jTable1.getModel();
line 2 error jTable1_d_t_model.delRow(row);

cannot find symbol
symbol: method delRow(int)
location: variable jTable1_d_t_model of type javax.swing.table.DefaultTableModel

see all my java method

but not delRow(int)


customise code for jTable1 in NetBeans


 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to call delRow() on a reference of type DefaultTableModel. But that doesn't exist in DefaultTableModel, it only exists in the anonymous class you've created.

You be able to use your method, you need to:
- Change from an anonymous class to a named one
- Cast the model to your model type, rather than DefaultTableModel
 
Rob Camick
Ranch Hand
Posts: 2608
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you even doing this? DefaultTableModel already supports addRow(...) and removeRow(...) methods. There is no need to override all those methods.

If for some reason you do need a custom TableModel, then you should be extending AbstractTableModel.
 
Paul Clapham
Sheriff
Posts: 21296
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:You're trying to call delRow() on a reference of type DefaultTableModel. But that doesn't exist in DefaultTableModel, it only exists in the anonymous class you've created.

You be able to use your method, you need to:
- Change from an anonymous class to a named one
- Cast the model to your model type, rather than DefaultTableModel


Or simply override the removeRow(int) which DefaultTableModel already provides.

(That covers the Java programming aspect of the answer; however the practical aspect is covered by Rob Camick's answer.)
 
Albert Robert
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot

Robert





Paul Clapham wrote:
Matthew Brown wrote:You're trying to call delRow() on a reference of type DefaultTableModel. But that doesn't exist in DefaultTableModel, it only exists in the anonymous class you've created.

You be able to use your method, you need to:
- Change from an anonymous class to a named one
- Cast the model to your model type, rather than DefaultTableModel


Or simply override the removeRow(int) which DefaultTableModel already provides.

(That covers the Java programming aspect of the answer; however the practical aspect is covered by Rob Camick's answer.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic