This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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)
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Instead of being a Vector of Appointments, the data Vector should be a Vector of Vectors of Strings. (Yes, read it again...)

To get the same data that you have specified into the table, you'd have to do something like this...



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
It's the error with DataVector you are passing as an argument to the constructor of DefaultDataModel.
The DefaultDataModel expects datavector being a Vector of Vectors in which
* Vector containing multiple Vectors(inner) resembling rows in a Table.
* The inner Vector contains elements resembling columns in each row.
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
It's the error with DataVector you are passing as an argument to the constructor of DefaultDataModel.
The DefaultDataModel expects datavector being a Vector of Vectors in which
* Vector containing multiple Vectors(inner) resembling rows in a Table.
* The inner Vector contains elements resembling columns in each row.
 
Don't get me started about those stupid light bulbs.
 
subject: JTable