• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem building JTable from ResultSet

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Currently, I'm trying to pass a resultset to a Table helper in order to return a table that gets added to a panel within a tabbedpane. When I launch, nothing shows except if I add the returned table to a JOptionPane and then it works fine. Not sure what I'm doing wrong as I normally do not work with swing

JTable Helper


JFrame where i'm trying to add the table
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron Ingram wrote:


Just because you give the instance field a different value, doesn't mean that the current table gets replaced. Remember, variables to objects are actually variables to references. By changing the value you're just letting the variable refer to a different object. The original object still remains the same, and that's what's being used in your UI.

Change the method to return a TableModel, and then call table.setModel(JTable_Helper.buildTableModel(rs));. This will set the model (backing data) of the existing table to your new table model.
 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!
 
Rob Spoor
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
I was her plaything! And so was this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic