Solved

How to memorize String value into jTextField

Posted on 2011-02-27
6
480 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:gbcbr
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now