persisting state of components of a JFrame

Hi all...
I like to ask what is the recommended way of persisting the state of 
components of a JFrame... for example the size and location of a JFrame, 
the text in a text box, the isSelected property of a checkbox, the 
selection in a combo box and so on.

There are two approaches i can think of.

1) to save their values as strings, one by one, in a properties file, 
and then read them the next time the application is started, and apply 
them to the components.

2) serialize the whole JFrame and save it to a file, then read it the 
next time the application is started and use it instead of creating a 
JFrame using "new".


method 2 is obviously less work to do. but i am not sure if it is 
better, or if it will really work well.

does anyone have experience in this area who can shed the light?
also, is there yet another way of persisting this information that i 
have not thought about?

thanks for any help.
0
hilz
4/7/2006 5:46:12 PM
comp.lang.java.gui 8307 articles. 0 followers. Post Follow

2 Replies
325 Views

Similar Articles

[PageSpeed] 29
How about to create Serializable class that will contain anything you need?
In this case you won't need to serialize whole JFrame,
but only its state(s).

hilz wrote:
> Hi all...
> I like to ask what is the recommended way of persisting the state of 
> components of a JFrame... for example the size and location of a JFrame, 
> the text in a text box, the isSelected property of a checkbox, the 
> selection in a combo box and so on.
> 
> There are two approaches i can think of.
> 
> 1) to save their values as strings, one by one, in a properties file, 
> and then read them the next time the application is started, and apply 
> them to the components.
> 
> 2) serialize the whole JFrame and save it to a file, then read it the 
> next time the application is started and use it instead of creating a 
> JFrame using "new".
> 
> 
> method 2 is obviously less work to do. but i am not sure if it is 
> better, or if it will really work well.
> 
> does anyone have experience in this area who can shed the light?
> also, is there yet another way of persisting this information that i 
> have not thought about?
> 
> thanks for any help.
0
Vova
4/7/2006 5:54:17 PM
hilz wrote:

> I like to ask what is the recommended way of persisting the state of
> components of a JFrame... for example the size and location of a JFrame,
> the text in a text box, the isSelected property of a checkbox, the
> selection in a combo box and so on.
> 
> There are two approaches i can think of.
> 
> 1) to save their values as strings, one by one, in a properties file,
> and then read them the next time the application is started, and apply
> them to the components.
> 
> 2) serialize the whole JFrame and save it to a file, then read it the
> next time the application is started and use it instead of creating a
> JFrame using "new".
> 
> 
> method 2 is obviously less work to do. but i am not sure if it is
> better, or if it will really work well.
Sun discourages you from method 2. See the API doc of JFrame (or any other
Swing component):
<quote>
Warning:  Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is appropriate for
short term storage or RMI between applications running the same version of
Swing. As of 1.4, support for long term storage of all JavaBeansTM  has
been added to the java.beans package. Please see XMLEncoder.
</quote>

> 
> does anyone have experience in this area who can shed the light?
> also, is there yet another way of persisting this information that i
> have not thought about?
3) encode the whole JFrame via java.beans.XMLEncoder and save it to a file,
then read it next time the application is started via java.beans.XMLDecoder
and use it instead of creating a JFrame using "new".

-- 
"Thomas:Fritsch$ops.de".replace(':', '.').replace('$', '@')
0
Thomas
4/7/2006 6:00:14 PM
Reply:
Similar Artilces:

Deploying Java component on Linux
I have created a few java components (jar ) on my Windows dev box and now want to run this on a Linux box for which I need MCR installed on the linux box. Where do I get the Linux MCR from? We at present run Matlab only on windows. ...

state of processor at the time of debugging
Hello All! What is the state of processor at the time of debugging a code through a debugger like gdb? Is it that the debugger is in total control of processor? How does the debugger control the speed/instructn executn rate of the processor? What is the status of processor at the time of break-point? ...

Multiple JFrame focus
Hi, I created a Java application that has a Progress window while it is loading. Using multithreading I have managed to create one and it works fine. What i want is for the main window to focus on the progress window all the time. In other words I do not want you to be able to see the main window by-itself whent he progress window is open. I am using JFrame for both of the windows. How can I do this? Thanks in advance Bojan wrote: > Hi, > > I created a Java application that has a Progress window while it is > loading. Using multithreading I have managed to create one and ...

CLOSE_WAIT state on sockets during high volume
Hi, I have a client/server application running and communicating using IP sockets. During high volume traffic many of the client sockets are stuck in a CLOSE_WAIT state (as determined by lsof). Eventually I reach my max open file limit and this causes all sorts of other problems forcing me to restart the application. Googling this problem revealed that it could be caused if the client is not closing the connection after it receives a FIN from the server. However, this does not make sense to me since every connection takes the same path through the code and the problem only surfaces when t...

SnODBC problems persist on Linux ! Please help
I dont seem to have any problems on windows. On Linux I tried many different version of tclkit (starkit) and from the shell commnad I get the error: % Symbol lookup failed for function: SQLGetDiagRec and when I run it within my website I get the error: Package Ffidl not found Can someone please shed some light on this ? Has anyone tried snodbc in linux ? thanks ...

[tao-users] TAO-IDL Compiler: 'component' keyword?
This is a multi-part message in MIME format. ------_=_NextPart_001_01C5D107.2D48111D Content-Type: multipart/alternative; boundary="----_=_NextPart_002_01C5D107.2D48111D" ------_=_NextPart_002_01C5D107.2D48111D Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From this IDL-compiler error: /home/tools/ace+tao-5.4.5/build/Linux-glibc-2.3-gcc-3.4-i386/TAO/TAO_IDL /tao_idl: "Component.idl", line 20: spelling differs from IDL keyword only in case: "Component" =20 Apparently the TAO-IDL compi...

Implementing State Space Equations in C language
Hi all, I have found out the mathematical model of a system in terms of 5th order state space equations by using system identification toolbox. I want to implement the state space equations in C language but i have no idea of doing this. Does anyone have done this before? Please share the code or a useful link. Any help will be greatly appreciated. ...

Persistence Model
I've been working on a generic persistence model for several years now. Checkout http://www.cutthecrap.biz for more information, but in brief: GPO (Generic Persistent Object) is a pure java-based persistent object model that provides a simple persistent mechanism to navigate general object associations : 1-many and many-many. Please checkout the main site and post any thoughts. Martyn cutthecrap wrote: > > I've been working on a generic persistence model for several years now. > > Checkout http://www.cutthecrap.biz for more information, but in brief:...

persistent break
I get the following error on SGI Indy: Warning: persistent break condition on serial port 0. Diagnostics failed. [Press any key to continue.] What could it mean? In article <gMBwh.47401$Nb2.901949@news1.nokia.com>, Zak. <zak@canspam.org> wrote: >I get the following error on SGI Indy: >Warning: persistent break condition on serial port 0. >What could it mean? A break is a "space", logic 0, positive voltage, held steady on the serial port input line for at least 125 ms. A persistant break would be if the line does not return to the resting ...

Vista upgrade to boost PC component costs by 20%
http://www.digitimes.com/systems/a20061211PR200.html >According to iSuppli, an average desktop PC running Windows XP contains >components that collectively cost PC OEMs slightly more than US$500. For >an average PC running Vista, the cost will jump to slightly more than >US$600, a 20% increase. Because this figure represents the cost of the >components and not the actual price of the PC, users will pay >significantly more than US$600 to buy a Vista-ready machine due to the PC >makers' added margins. >Although Microsoft has stated that 512MB of DRAM will be suffic...

Security firm falls prey to breach / Attack considered 'persistent threat'
Security firm falls prey to breach Attack considered 'persistent threat' By Hiawatha Bray Globe Staff / March 19, 2011 RSA, a Bedford security systems maker whose products guard vital computer networks worldwide, was scrambling yesterday to recover from a security breach that could expose its customers to hacker attacks. The attack, revealed on Thursday, compromised products RSA sells under the SecurID brand name. RSA, a division of data storage giant EMC Corp. of Hopkinton, called the attack an ''advanced persistent threat,'' industry jargon for a ...

Chart Component
I am looking for a chart component comparable to http://chart2d.sourceforge.net/ ...

Which persistence is for me?
I need to organize the results of some experiments. Seems some sort of database is in order. I just took a look at DBAPI and the new sqlite interface in python2.5. I have no experience with sql. I am repulsed by e.g.: c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""") ewww. How unpythonic. I don't want to use a string to specify what function to execute. I want to call a function (c.insert?). Is there some other interface/database that I might like better? On 1 Nov, 11:47, Neal Becker &...

Re: installing SAS
Try to stop everything which might be running. Detatch the computer from the network and stop all anti-virus, anti-spam, anti-anything software and firewalls. Start the task manager to control, what might be running still. Perhaps have a look on all the autoexec, autorun in registry, ... - stuff, deactivate them and restart the system. How ist it now, when you install on your fresh-booted windows? Not better? Can you deinstall the MS runtime-components? If you have the chance, do it and try to reinstall that tool from scratch. Hope you are successful! Gerhard On Fri, 22 Dec 2006 04:30:34 -...

assignment of coarray objects with allocatable components
Hi all, So I was reading the g95 site the other day and found this paragraph: "... sent in an illegal coarray code he had a derived type that he was assigning across images. On a regular code, this causes allocations to be copied. On a coarray code, this would have been hideous to implement. Fixed. It turns out to be legal to pass around derived types that contain pointers, but the pointers are considered to be undefined on different images." This got me thinking, why not? Allocatable coarray subcomponents are allowed. I understand that image A cannot allocate anythi...

State of Nuitka
I thought this might be of interest http://nuitka.net/posts/state-of-nuitka.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ...

Persistent Cookies
I am having a problem with some javascript cookies and IE. First let me show you the example : http://dev.webnonsense.org/cookie-menu/ So 'Toggle Tools' Shows or hides the text above the nav and when you browse away from the page by using the 'other' link it is supposed to remember its state. It works fine in Firefox and Safari for the Mac and Firefox on the PC, but it does not remember its state in IE 6, and I am not sure about IE7. I am all out of ideas. Thanks On Feb 14, 9:50 pm, "anathema" <spamfreeunive...@gmail.com> wrote: > I am having a problem ...

Persistent map implementation in Scheme?
Anyone have an efficient persistent map implementation written in Scheme? Such as, for example, an implementation of the persistent version of the red-black tree algorithm? By "map" I mean an associative array or a dictionary, commonly implemented by a hash table (though in my application I could use a tree with comparable keys instead): a data structure that maps keys to values. A "persistent" data structure preserves the previous version of itself when modified. [http://en.wikipedia.org/wiki/Persistent_data_structure] Naturally, purely functional data structures are au...

TIP #197: Text Widget Persistant Cursor
TIP #197: TEXT WIDGET PERSISTANT CURSOR ========================================= Version: $Revision: 1.1 $ Author: R. Timothy Edwards <tim_at_stravinsky.jhuapl.edu> State: Draft Type: Project Tcl-Version: 8.4 Vote: Pending Created: Wednesday, 12 May 2004 URL: http://purl.org/tcl/tip/197.html WebEdit: http://purl.org/tcl/tip/edit/197 Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes a simple extension to the Tk text widget to allow the in...

Custom JFrame Header
Hi again, Is there any way one can customize the header ( the one which holds the title of the frame along with Minimize,Maximize and Close buttons). Customization could mean changing the color and changing the image-icon that comes, for example in case of Java Applications, the image-icon that comes is that of a cup. Regards, Ankur hellbent4u@gmail.com wrote: > Hi again, > > Is there any way one can customize the header ( the one which holds the > title of the frame along with Minimize,Maximize and Close buttons). > Customization could mean changing the color and changing...

state space #10
how can i design a pid controller in state space method. Is the state space can be done only in matlab. how can i use it in plc. pls give me the reply at the earliest On Aug 13, 10:10=A0am, "Anjana " <anjanagnair...@gmail.com> wrote: > how can i design a pid controller in state space method. buy text book >Is the state space can be done only in matlab. yes >how can i use it in plc. what is plc > =A0 pls give me the reply at the earliest see the above for the reply ...

Data on Ohio State Workers Stolen
By STEPHEN MAJORS, Associated Press Writer A data storage device with the Social Security numbers and other personal information on all 64,000 Ohio state employees was stolen from a state intern's car last weekend, Gov. Ted Strickland said Friday. "I don't mean to alarm people unnecessarily," Strickland said. "There's no reason to believe a breach of information has occurred." He said it takes special equipment to access the information on the device, so he doesn't believe the workers' privacy is in jeopardy. Strickland said an Office o...

State of interrupt flag when IntConnected routine is called?
VxWorks 5.4.2 Tornado 2.0.2 Pentium target When a hardware interrupt occurs, and VxWorks calls my intConnected routine, are the interrupts at the processor level still disabled, or are they enabled? Ignacio G.T. escribi�: > VxWorks 5.4.2 > Tornado 2.0.2 > Pentium target > > When a hardware interrupt occurs, and VxWorks calls my intConnected > routine, are the interrupts at the processor level still disabled, or > are they enabled? They are enabled. Proof #1: From VxWorks User's Guide, 5.4, D.4 (Architecture considerations for ix86): Interrupts and Exceptions...

Java Swings: Adding JButton to JFrame
Dear All, I have a problem in the following code.....I was unit testing the code from main(). I have the FaMain base class for creating the window with certain features. So I need all my child windows to inherit FaMain class. Similarly, I need FaButton as base class instead of JButton. But even after creating two buttons but1 & but2 only the second button but2 is getting appeared......Please help me....... import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006<...

arithmetic persistence
A Sunday topic... I bought not long ago a deck of cards with mathematical puzzles (question on the face, answer on the back) by Martin Gardner. One puzzle dealt with the issue of /persistence/ in the mathematical sense. Take an integer (decimal representation). Take the product of the digits its representation is made of. This gets you a new, smaller, number. Recurse until the representation takes a single digit. The persistence is the number of steps it took. Unclear? Sorry I gave the deck to a friend. But 0 is the first number of persistence 0. 10 is the first of p(1). 25 is t...