This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating Jtable entries from user inputted data?

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program where it's main function is a calculator for various things. After calculation I have a button called "save" where the user can save the data to a JTable row. I want a row to be updated every time I click save. I'm not sure exactly how to update the row, and how to do it on the fly. I know there are table models and such, but do I have to create a new one every time and just update that? I've also seen things such as but I'm not sure exactly sure if this just gets it ready for editing, because I see , ;, and such.

Any help would be appreciated, thanks!

~Jay
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All components in Swing have a model which holds their data.
For JTable, it is TableModel. Every JTable, by default, has a model named DefaultTableModel (what else!?) associated with it.

You can get a reference to this table model with the call:
and then, you can make use of the methods like setValueAt(aValue,rowIndex,columnIndex) to set the value of a particular cell. This method also takes care of notifying the view which then updates the table view.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:All components in Swing have a model which holds their data.
For JTable, it is TableModel. Every JTable, by default, has a model named DefaultTableModel (what else!?) associated with it.

You can get a reference to this table model with the call:
and then, you can make use of the methods like setValueAt(aValue,rowIndex,columnIndex) to set the value of a particular cell. This method also takes care of notifying the view which then updates the table view.


Thank you so much, that's exactly what I needed!
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic