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

Debug Components with a Custom Glass Pane #96
Chapter 12, Miscellany
|
481
HACK
from/subject of one email message, the details of a downloaded file, etc.). In
cases like these, I’ll try to see if a
JList with a multi-line cell renderer [Hack #16]
can keep all the data together in a visually pleasing form. So, when is hori-
zontal scrolling OK? I think it’s appropriate when the data you’re displaying
is not row-oriented, and instead you’re scrolling up, down, and across a
single cohesive thing, like a large image or, in this case, a stack trace.
H A C K
#96
Debug Components with a Custom Glass PaneHack #96
Show component boundaries at runtime using a glass pane.
Sometimes when I’m building a really complicated Swing layout, I start to
lose track of what I’m looking at. Which component is this? Does that panel
extend all the way to the end of the frame? A way to visualize the layout
would be a useful addition to the usual development tools. This hack
explores using a custom glass pane to highlight each component and its
classname.
A glass pane is a normally transparent Swing component that is drawn on
top of all of the other components in a frame, as you saw when you put
dialog-like “sheets” into the glass pane
[Hack #44]. It is this ability that forms
the center of the hack. The custom glass pane will traverse the entire tree of
components in the frame, filling a translucent rectangle over each compo-
nent. Deeper components will get painted multiple times resulting in a
darker color. The glass pane will also watch the mouse cursor to determine
which component the user is pointing at. That component’s classname will
then be drawn in the glass pane as well.
Figure 12-10. Capturing standard out and err to Swing windows

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