272
|
Chapter 7, Text
#51 Write Backward Text
HACK
One question you might ask about this implementation is
“why stuff a
JList in a JWindow you have to manage, when
you could just use a
JPopupMenu?” Good question, but one
with a pretty straightforward answer: the
JPopupMenu is
modal, so once it appears, clicking on it is the only option.
That’s not the desired behavior here, where clicking in the
menu is optional, and the more likely circumstance at any
time is that the user will continue typing. So, the better
approach is to let her keep typing and just keep track of the
possible completions.
H A C K
#51
Write Backward Text Hack #51
Baffle your friends by turning their text into its mirror image.
The fact that everything in Swing goes through the Java2D rendering pipe-
line makes it really easy to apply all sorts of effects to Swing components.
Text offers some fun possibilities. For one, you can challenge the user by
turning his text into a mirror image of itself.
Figure 7-5. One completion removed after typing two characters
Figure 7-6. Another completion removed after typing six characters
Figure 7-7. Text field filled in by clicking on completion from list

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.