Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem building JTable from ResultSet  RSS feed

 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the help!
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!