File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problem in displaying data in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in displaying data in JTable" Watch "Problem in displaying data in JTable" New topic
Author

Problem in displaying data in JTable

KathySmith SmithL
Greenhorn

Joined: Oct 17, 2004
Posts: 10
hi, can anyone tell me what I'm doing wrong here? The data is coming from a db and is stored in the alrtRslts vector. The data in the alrtRslts vector is correct. The print statement prints the data correctly.
I'm getting a classCastException when I create new JTable(data, heading).
Pls help me solve this.. I need this urgently..

[ November 01, 2004: Message edited by: KathySmith SmithL ]
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
To use this technique when creating JTables, the first argument (i.e. rowdata) to new JTable() must be a vector of vectors.

You are using a vector.
KathySmith SmithL
Greenhorn

Joined: Oct 17, 2004
Posts: 10
Thanks, I tried that.. there won't be any exception, but the display is still not coming.. is there anything else that I need to add?
Here's my changed code:

jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
Are you saying that your new code executes without any errors?

Is your problem now, that you don't see your data in your table?

Or is it that you don't see your table at all?
KathySmith SmithL
Greenhorn

Joined: Oct 17, 2004
Posts: 10
The new code executes without any errors.. but the table is not displayed correctly and also there is no data in it.. all I see is just a block of white patch on the GUI
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
Can you post any of the code you use to display it?

What I'm thinking is that you have created and displayed a table. Then you called this method. Which would have the affect of building a new table but never displaying it.

It's just an assumption.
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
here is a quick and dirty application that may help you out.



Just cut and past it. I tried to use your conventions to make reading it quicker.
KathySmith SmithL
Greenhorn

Joined: Oct 17, 2004
Posts: 10
This is all the code I have to display the data in the jtable. Doesn't the stmts,
jtbl_Alert = new JTable(mydata, heading);
and
jtbl_Alert.setVisible(true);
display the data? Is there more to this to display the data seperately? This is all I found in the examples..
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
check out the code I posted.

Let me know if you can get it to work or not. It should be easy enought.

Create a testing package, copy and paste my code into a new class called tableTest and run it.
KathySmith SmithL
Greenhorn

Joined: Oct 17, 2004
Posts: 10
Thank you so much.. it works fine now.. I just added the part where u are adding the code setPreferredScrollableViewportSize and adding it to the scrollPane and it worked like a charm.
 
jQuery in Action, 2nd edition
 
subject: Problem in displaying data in JTable
 
Similar Threads
JTable
JTable
JTable ........
Color in JTable
Columns on JTable