This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Trying to populate JTable with resultSet 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 "Trying to populate JTable with resultSet" Watch "Trying to populate JTable with resultSet" New topic
Author

Trying to populate JTable with resultSet

tom davies
Ranch Hand

Joined: Apr 27, 2012
Posts: 168
I am using an example and trying to make it work with my own program. I have a JComboBox with the names of my database tables in. I am able to display them by printing the result set but i now want to add them to a JTable. Below is what i currently have, but it doesn't return anything, the scren stays blank.



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

How many records does your table have? If the number is quite high, then the calls to last() and absolute(...) will take quite long, effectively blocking the event dispatcher thread.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
tom davies
Ranch Hand

Joined: Apr 27, 2012
Posts: 168
Rob Spoor wrote:How many records does your table have? If the number is quite high, then the calls to last() and absolute(...) will take quite long, effectively blocking the event dispatcher thread.


Maximum of 6 at the moment, so not enough to cause a problem.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



As far as I can see you aren't adding this JTable to your GUI. Did you perhaps already create a JTable object, assign it to that dTable variable, and put it into your GUI in some initialization code? If so, then assigning another JTable object to the variable won't have any effect on that. Remember, the components you add into your GUI are objects, not variables.

So (again, if I guessed right) don't create a new JTable. Use the one you already have instead:



tom davies
Ranch Hand

Joined: Apr 27, 2012
Posts: 168
Paul Clapham wrote:

As far as I can see you aren't adding this JTable to your GUI. Did you perhaps already create a JTable object, assign it to that dTable variable, and put it into your GUI in some initialization code? If so, then assigning another JTable object to the variable won't have any effect on that. Remember, the components you add into your GUI are objects, not variables.

So (again, if I guessed right) don't create a new JTable. Use the one you already have instead:





Ahh yes, you did guess right. It is working now i am using dTable.setModel().

Thank You!
 
Don't get me started about those stupid light bulbs.
 
subject: Trying to populate JTable with resultSet
 
Similar Threads
AbstractTableModel NullPointerException
JTable & JDBC
Slight JTable problem
removing a scrollpane, yet still see it
Jtable CellEditor