?
Solved

How to memorize String value into jTextField

Posted on 2011-02-27
6
Medium Priority
?
507 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 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