File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


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
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
at javax.swing.table.DefaultTableModel.<init>(
at javax.swing.JTable.<init>(
at SimpleTableDemo.<init>(
at SimpleTableDemo.main(
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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]

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

no GOD except ALLAH...
I agree. Here's the link:
subject: JTable
It's not a secret anymore!