• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Populate JTable With Database Data

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to populate a JTable from a jButton event with data that I'm retrieving from an sqlite db. I have no trouble connecting to database and populating the 'data' and 'row' vectors but when I try to pass them to my JTable (jtblReqList) it does not seem to populate. I am under the impression that I should be able to popluate the JTable with the data contained in the vectors without using any of the table models. Any help is appreciated....thanks.

 
Sheriff
Posts: 28321
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're creating a JTable, but I don't see what that has to do with your GUI. I don't see any code where you add that JTable to any GUI.

Typically what you do is to create a GUI, including a JTable. Then when you get the data from the DB you put it into a DataModel, then update the existing JTable by calling its setModel() method (warning... name of method pulled from unreliable memory). Creating a new JTable is generally pointless as it isn't part of the GUI. Trying to get it into the GUI is also difficult to do, but since setting the data model of the one which is already there works, you don't need to futz with that either.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Joe!
Can you please UseCodeTags from now on? I've added them for you, and you can see how much easier it is to read your code.
 
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be this link will help you.

http://www.onlinexamples.com/showfullexample.action?idexamples=76&title=Update%20Jtable%20Dynamically%20In%20The%20Gui%20Say%20For%20E.g.%20In%20A%20Jframe
 
Joe Mastro
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome, thanks everyone. As Paul stated there was no reason to create a new JTable when I already had one existing on my JFrame. I used the DefaultTable model in Nitin's link and set my JTable (jtblReqList) to the model and this at the very least populated the JTable.

 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic