Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Problem building JTable from ResultSet

 
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
 
Sheriff
Posts: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic