• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

jTable Insert/Update not working from another class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to call a method from another class that will add data to a jTable but the data doesn't show up in the table.  If I add data from within the class that creates the table model, it works fine.

This works fine from Gui_Main:


This does not work when called from the Product class:


I've been able to confirm that the program flow is hitting the addData method by inserting a variable in the addPart method and showing it in the addData method.  I've tried doing table refreshes and all other kinds of Java acrobatics to make this work based on other researched examples but have so far come up empty.  Can anyone point me in the right direction?

Thanks!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Penney, and welcome to the Ranch!  You're probably adding the data to an instance of Gui_Main that is different from the one you have displayed.  I say 'probably' because the code snippets you have posted are really not enough to diagnose the problem.  To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example).

Also, to conform to Java conventions, that class could be named GuiMain, not Gui_Main (it would be better still if the class name implied its purpose).  Your package names Parts, Products and Inventory should be lowercase i.e. parts, products, inventory.

Since this is a Swing and not a JavaFX question, I've added it to the correct section of the Ranch.
 
Penney Eldendl
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK.  I've redone the code to be more a more complete reflection of what I'm doing.



Here's the other package that I'm trying to call from.  I've made it so that it is simply a "Save" button that will call the method and theoretically should add another 4 lines to the table but it doesn't.



Let me know if there is anything else needed to clarify what I'm trying to do.  You should be able to just copy/paste this code into your IDE and run it.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all class names should start with an upper case character. Have you ever seen a class from the Java API not start with an upper case character? Follow Java conventions.


As suggested by Darryl, you are creating a second instance of the "CodeRanchTable". Don't do this?



You pass a reference to the "CodeRanchTable" as a parameter to the dialog, so just save the reference to a variable and use the variable in your actionPerformed() method.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic