views:

52

answers:

1

I'm using Java Preferences API to store window position and size of Swing application. At this moment, I'm listening to window resize/reposition events and storing the position and size every time they change. However, that means that if user slowly resizes window which is 200px wide to 400px wide, I'll probably write new window size about 200 times during pretty short time.

Preferences API uses whichever datastore is available on the host system (windows registry for Windows etc.) - but the question is, what are limitations or best practices for properties API? Is it OK, or would it be smart to write only when user has finished resizing? Anyone had experiences with Properties API on different platforms?

+3  A: 

Just re-read and realised you're talking about the app itself not a dialog, but the concept probably still applies: record the dimensions only on successful application shutdown. I think this would be perfectly fine for most users / situations.


Why not record the new size only on "OK" or "Cancel" button event? I.e. don't store it dynamically.

If it's modal, you cannot lose anything by doing this, it's just the final value you want. Who cares if it was 307 px for a millisecond?

Brian
Hi Brian - yes, that's one way to do it and I've thought about it, however my question was really about the API itself, and the window resizing was just an illustration of the problem. But let's say that I want user to continue where he left even if my app crashes and fails to execute shutdown hook. Actually, even more so if it crashes, kind of like Opera which restores complete state after the crash.
Domchi
Ah ok; not really worked with the API. For anything that's NOT firing loads of events I would guess you're probably OK with fairly regular preferences saves, regular being perhaps every few seconds when stuff changes though, not many times per second. As I say though, just speculating here :-)
Brian