Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable

 
Gerald Spica
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
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic