aspose file tools*
The moose likes Java in General and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JTable" Watch "JTable" New topic
Author

JTable

Gerald Spica
Ranch Hand

Joined: Jul 28, 2003
Posts: 30
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)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
F A H A D
Greenhorn

Joined: Aug 16, 2003
Posts: 13
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...


no GOD except ALLAH...
 
wood burning stoves
 
subject: JTable