• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JTable

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
a:238)
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
ava:194)
at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:131
)
at javax.swing.JTable.<init>(JTable.java:392)
at SimpleTableDemo.<init>(SimpleTableDemo.java:29)
at SimpleTableDemo.main(SimpleTableDemo.java:70)
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
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
Bye...
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic