• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling jTable.getModel().setValueAt() from other package/class.

 
Sebastian Ossandon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need to load text from a .txt file to a jTable. The structure of the classes is this:


And from MainController I need to fill the table in MainFram with the values of the arrayList. I'm using this:


But the table (called Tabla) is not in that class and if i do something like mainFrame.Table, it says it is a private variable.
What should I do?
I'm new to this. Thanks.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sebastian,
Welcome to the Ranch!

Forgetting the GUI for a moment, think about this - it is a good practice in OOPS to provide a method to access a private variable. So, you can do that in the MainFrame.java.

an even better approach would be to provide a method in MainFrame which accepts a List<Personaje>. You can then have this loop within that method which in turn sets the value.
 
Sebastian Ossandon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give me an example of that, please?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Ossandon wrote:Can you give me an example of that, please?

In pseudo code

1) Define private MainFrame INSTANCE in your MainFrame class
2) In your MainFrame constructor initialize INSTANCE to this.
3) Define a static getInstance() method in your MainFrame which returns INSTANCE
4) Provide a pass through method as suggested by Ranga above which accepts List<Personaje>

If you run into any problem post your SSCCE code so we can help you figure out whats going wrong
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!