• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in displaying data in JTable

 
KathySmith SmithL
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic