Solved

How to memorize String value into jTextField

Posted on 2011-02-27
6
487 Views
Last Modified: 2012-05-11
When I open GUI, all values entered during previous session into text fields disappear.
Please advice how to remember last entered value into text field, so I don't need re-enter it again.
Thank you
0
Comment
Question by:gbcbr
  • 3
  • 3
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 34992362
If you want to have on the start of application the same values
in textfields which user entered last time you need to persist
what user eneterd previous time in the file or i database
0
 

Author Comment

by:gbcbr
ID: 34992373
I heard a lot about persistence, but for me now it's black box.
Can you suggest how to start to develop it?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34992545
Well, then it si totally different question - if you want to
learn perisistence for some parcatical reason, maybe you want
to read about object serialization and store you objects in files or database,
you may use Hibernate which does for you part of yoyr tasks or use Persistence API:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/persistenceapi/

But if your goal is to make sure next time folks start your program
they see the same textfileds they left it when tey last used it then all this stuff
is more of an overkill.

Basically, as a reasonable middle way, I'd suggest to make a Properties
object to collect all tese data in that object when you
run through your program and befiore you exit to serilize this object
into configuartion file, maybe to write it instead into
XML file or .property file is a better option then you can modify it in the meantime.

And then on startup you read it in.

There is an example of such thing in this link (click on Listing A) for the code:

http://www.techrepublic.com/article/store-your-apps-configuration-information-with-java-properties/1049436
 



 
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:gbcbr
ID: 34992599
I suppose that is what I need in my case. Just I need to understand how to connect it to my GUI.
I'll study it tomorrow.
Thank you.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34992624
I think you rather think of this stuff as the data ssociated not with GUI
but as parameters associated with your program, which you
naturalyy pick up through your GUI.
So at time when you get hold of these parameters you store them in
some object which lives wthin your program
When you ultimately leave your program you make sure you put in some good place this
object amd on start up even before you create
and populate your GUI
you just first check if there is an object stored previous time
These things are indeed more like configuration of your program
and you can store there initial values of yout textFields together
with say preferable paths for writing files.

Have a good evening.

0
 

Author Comment

by:gbcbr
ID: 34992694
Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
How to determine if a string is a valid SHA value 7 35
printf performancy 11 70
Bot application - advice 3 38
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question