Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JTable  RSS feed

Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a Jtable using Vectors. When I compile the code I get the following error. What is the cause of this error?
C:\j2sdk1.4.1_04\bin\dev\Table>java SimpleTableDemo
Exception in thread "main" java.lang.ClassCastException
at javax.swing.table.DefaultTableModel.justifyRows(DefaultTableModel.jav
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
at javax.swing.table.DefaultTableModel.<init>(
at javax.swing.JTable.<init>(
at SimpleTableDemo.<init>(
at SimpleTableDemo.main(
author and iconoclast
Posts: 24220
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The two arguments to the JTable constructor you're using are supposed to be a Vector of Vectors of cell contents, and a Vector of Strings. You're passing, instead, a Vector of Appointment objects, and a Vector containing a single AppointmentHeader object. I can't be sure what your intention is, but I think you want to do something like (code deliberately direct and straightforward, you could certainly use loops ...

If you want to take the data directly from your business objects, then you need to write your own custom TableModel.
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u have to add the field in the Table by using 2D Array or set the vector in the Table. If u want to add the field dynamically u have to uise the DefaultTableModel. I suggest u to use DefaultTableModel.
Take Care
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!