This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 24183

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
Similar Threads
how to execute simple swing program
Simple GUI Question...........
Boolean Question in Sun sample prog
iscelleditable is not working in jtable