0

I am writing a GUI application in Java, where I am supposed to add, delete and edit some items in a JTable. The table is located in one JFrame where I also put buttons for adding, editing and deleting. When I click on the add button, it opens a new frame where I put in the data about a specific object, then that object goes into the table of the previous form and also goes into an ArrayList of such objects. The adding works great.

Now, when I want to edit an item, I select it from the table and want to open the same frame which I use for adding. The form gets populated with the data of the selected object and I edit the data and want to save it to the table and the array list in such way that only the edited object gets saved and the original gets deleted. Here I have some problems.

Does anyone have an idea on what the best way to do this would be?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
ivana14
  • 107
  • 8
  • 1
    If you have the index of the original object, you can just use `ArrayList#set(int, Object)` to replace one object with another - you could also simply update the original object and trigger and update of the `TableModel` – MadProgrammer May 22 '17 at 11:06
  • 1
    1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson May 22 '17 at 12:02
  • @MadProgrammer it worked, thanks – ivana14 May 22 '17 at 12:58

0 Answers0