Solved

How to memorize String value into jTextField

Posted on 2011-02-27
6
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Industry Leaders: 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

Suggested Solutions

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

734 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