Chapter 7, Text
#51 Write Backward Text
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
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
H A C K
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