O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required