Get your CodeRanch badge!*
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 Java 8 in Action this week in the Java 8 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable
 
Similar Threads
Boolean Question in SimpleTableDemo.java Sun sample prog
Simple GUI Question...........
JTable
iscelleditable is not working in jtable
how to execute simple swing program