Python Rocks! and other rants 17.10.2004
Weblog of Kent S Johnson

2004-10-17

Sticky Widgets

A technique I am using quite a bit is to make sticky widgets - GUI widgets that autonomously remember some part of their state. For example, a text field that remembers its last value; a window that remembers its last size and shape; a file dialog that remembers the directory it last showed.

These widgets make it very easy to create a user interface with some persistent state. This saved state makes the GUI much easier on the users.

In my case the widgets are written in Java using Swing. Each widget takes a preferences key as a constructor argument. The given key and the class name make the full key. This allows the widget to save and restore its state without reliance on any application globals, and without writing any application code specifically to handle the stickyness. The widget registers itself as a listener to itself so it is notified when its state changes and it persists its new state.

This is work code so I won't post it but it is really pretty easy to do and very handy.

posted at 14:57:04    #    comment []    trackback []
October 2004
MoTuWeThFrSaSu
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
25262728293031
Aug
2004
 Nov
2004

Comments about life, the universe and Python, from the imagination of Kent S Johnson.

XML-Image Letterimage

BlogRoll

© 2004, Kent Johnson