Save JTable Changes Before Doing An Action

Let’s say you have a JTable component and a save JButton in a form. When you make changes to the data in the JTable, the cell editors would have to save the new changes before you will be able to get the new values. One thing you probably did was to click on some other cell so that the previous cell would lose focus and the new changes will take effect.

But what if you want to click on the save JButton in order to save all the data in the JTable? It is ugly to have to click on some other cell so that changes will take effect and then clicking on the save JButton.

There is a way to go around this and it only involves one line of code.

Place that line of code inside your JButton‘s actionPerformed() method before doing any save. That way, you will be able to get the new values in your JTable.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *