• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

return previous value of jTextField

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a simple question but I couldn't figure out how to solve it.
It is related to save and get jTextField values, for example:
1. User typed some text on jTextField1 ( for example, "text 1") and clicked Save Button.
2. User cleared "text 1" and typed new text "text 2", but Save Button doesn't clicked.
3. If a user doesn't click Save Button then jTextField1 should return previous value "text1".

I would like to ask how to return previous value of jTextField1 i.e "text 1" when Save Button doesn't hit?
Any help is really appreciated.
 
Marshal
Posts: 74014
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slightly strange requirement. Please explain more. Do you mean are you going to save a snapshot of the program state. Are you going to have a file where you save the contents of the text field? Are you going to restore it from that file? Are you going to save the entire GUI (remember all Swing components count as beans) in XML and restore the state when you open a new GUI?
 
Campbell Ritchie
Marshal
Posts: 74014
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you going to wrap the text field in a wrapper class which records the old value? What do you know about listeners on a text field? You may need a document listener.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Content menu with several jPanels (jPanel1, jPanel2), and every jPanel is referenced by CardLayout. Every jPanel has textfields and comboboxes and Save Button. After filling textfields we click save Button, it will save to text file. Also there is have Load Button which loads saved data to textfields. The problem that I am facing is when I modified the text on textfiled (jPanel1) then without clicking Save Button I moved to jPanel2 (CardLayout), and when I return to jPanel1, the modified text on textfield is still shown. I found a solution in combobox case from this link. Similar one I want to implement to textfields too.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you determine that a Save button has not been clicked?

In other word, what is it the user has to do to say "I am not saving this"?

Is it a Cancel button, for example?
 
Campbell Ritchie
Marshal
Posts: 74014
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like an implementation detail; you need to explain the concept behind what you are trying to do first. Look at this FAQ. You may  to put listeners on the frame which revert the text to its old value whenever that pane is hidden.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Dave Tolls  I didn't think include Cancel Button, maybe some JOptionPane with a message "Do you want to save changes?", then reset to the previous value.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we cross posted.

If the user action is "moving away from the pane" then, presuming the data is not moved from the GUI to the Model unless Save is clicked, then the issue seems to be not a case of reverting, but a case of populating.

That is, when the user goes to the editing panel then that panel should be populated from the Model and not from whatever data was previously held in the GUI.
 
reply
    Bookmark Topic Watch Topic
  • New Topic