This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

I want to populate a jtable with data read from a database  RSS feed

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written the following code and I cannot for the life of me figure out what is going wrong.  When I run the program, nothing happens but when I exit the GUI, the data is writtencorrectly  via System.out.println to my netbeans console.  Please tell me what Im doing wrong

 
Marshal
Posts: 63783
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know; I have forgotten everything I ever knew about JTable. I suggest you go through the Java™ Tutorials about JTable and maybe also the JDBC tutorial.

Why are you mixing dialogues, java.awt.Frame and JTable? That doesn't look right. Don't use AWT components; use a JFrame and forget about dialogues for the time being.

Moving to our GUIs forum.
 
Campbell Ritchie
Marshal
Posts: 63783
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are all those columns in the database CHAR or VARCHAR type? If not, why are you fetching them all as Strings?
 
Rancher
Posts: 3983
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the CustDisp (which ought to be custDisp) method called?

When you say "nothing happens", presumably the GUI displays?
 
Shashank Gokhale
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, I realized I didnt call all the methods I should.  Anyways here is  a new piece of code, and Ive called all the right methods in the constructor.  When I run the program, yes the JFrame is displayed but the data that is read from the database does not get get listed in the jtable.  The data is properly put into the set of row objects, as I used a system.out.println statement to find out.  So Im thinking that for some reason the table.addRow(row) is not displaying the data to the jtable.  Or is there something else Im missing

 
Shashank Gokhale
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay i think Ive got that figured out.  The rows that were aready present in the jTable were the ones showing up, and while the populated rows were being added, they were outside the lower boundary of the JTable, and so I couldnt see them.  So basically I deleted the empty rows that were in the JTable component.  But I cant get the insert, update or delete buttons to make changes to the Table, at least i dont see any changes
 
Master Rancher
Posts: 3026
21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Way too much code.

Your question is about a JTable, so instead of writing an entire application you first need to learn how to use a table.

So you start by creating a JTable with hard coded data in one or two columns and display this on a frame.

Then you create an "Add Row" button to add a new row of data to the table. Again, this data will be hard coded.

Then you create a "Remove Row button.

Then if you have problems you can post your simple code. This simple code is called a SSCCE and should be created when you are learning a new concept.

Finally once you get you basic functions working in the SSCCE, then you can make your code dynamic with SQL.  Then all that changes is the code in your "Add Row" button and your "Remove Row" button so if the code stops working you know what you modified and know where the problem is.

 
Shashank Gokhale
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, it is a lot of code, basically I pasteed everything that was generated by Netbeans and stuff, but basically the thing is that when I have an sql table, and I modify the table, I want to find a way of displaying the updated table each time in the jtable.  Should I delete all rows of the jtable by setting setRowCount to 0, and then repopulating or is there a better way
 
Rob Camick
Master Rancher
Posts: 3026
21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


basically the thing is that when I have an sql table, and I modify the table, I want to find a way of displaying the updated table each time in the jtable.  Should I delete all rows of the jtable by setting setRowCount to 0, and then repopulating or is there a better way



That is one way.

Another way is to update the database and the JTable at the same time.

There is no automatic way to have the JTable updated when the database is updated.
 
Shashank Gokhale
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Okaiy, I have just listed the methods that are supposed to make the jtable show the correct info, but the jtable isnt showing the right info.  When I modif the sql table through code, the sql table is changed, but then to display the latest table, I need to read from the table and add rows to the jatable.  But for some reason, its not working that way, Ive got a for loop in the first method (the insert method) that removes all the rows and then I call the display method to read and display the table, but its not working.  And I dont know why


>
 
Dave Tolls
Rancher
Posts: 3983
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the userList populated, as that is what the TableDisp (which should be tableDisp, or even better displayTable) method uses to populate the JTable.
There's nowhere, after you edit or change the data in the database, that you reload the userList.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!