Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving DefaultTableModel from JTable

 
Hewa Naimanage Sumedha Amalka
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I need to get DefaultTableModel from my exsiting Jtable; I am using Java 5.0 and when I use

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

sends me a
java.lang.ClassCastException
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need the table to have a DefaultTableModel, either construct it with a DefaultTableModel or setModel to a DefaultTableModel.

If the table's model isn't a DefaultTableModel, you can't cast it as such.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic