I am new to Java Swing and I am creating a window which displays a list of items retrieved from an XML file that can be manipulated by the user. The window should have a Cancel and a Save functionality implemented with buttons. While the Save functionality is straightforward (just close the window) I don't know how to implement the Cancel functionality. Does exist an "undo" function? Does anyone know how?
Can't you make a loop that iterates throught all the fields; changing all values in the fields to null for cancel and then close the window?
it depends on whether you have a modal or modeless window/dialog for a modal/dialog window you should ask the other way around: first store you values when the user clicks save/OK.
for a modeless window you could hold a copy of your data thats editable in the window in your window and save when the user clicks save and do nothing when the user clicks Cancel
If it is about to restore the internal (changed) datas tructure for subsequent processing, you could either duplicate the data before editing, or simply reread the XML file. If you don't need the data any longer simply do nothing on cancel (but closing the window).