Java preferences API throughput
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?
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?
精彩评论