wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Updating Jtable entries from user inputted data? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Updating Jtable entries from user inputted data?" Watch "Updating Jtable entries from user inputted data?" New topic
Author

Updating Jtable entries from user inputted data?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

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

Joined: Oct 16, 2003
Posts: 1076
    
  10

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.

Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

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

Joined: Oct 16, 2003
Posts: 1076
    
  10

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating Jtable entries from user inputted data?
 
Similar Threads
adding a blank row to a JTable
JTable
Wanted: conceptual tutorial on JTable
Help updating cells in a JTable
JTable Paging