Skip to main content

Non-subclassed Swing enhancements

No replies

The blogs of Santhosh Kumar have been mentioned recently. He's been
steadily streaming out a bunch of Swing tricks.

One approach he seems to favor is to externalize behavior using a
wrapping technique, rather than subclassing and creating special
components. An example is his latest, a hyperlink for Swing,

instead of creating a hyperlink component, he has a function that adds
a mouse listener that switches borders on a mouse hover.

I like this approach (I think the example he showed is ugly, but the
point is clear). The downside with subclassing is that since we don't
have multiple inheritance, you either get a very wide set of
subclasses mixing different behaviors, or massive superclasses that
can do everything, with behavior switched on or off.

Just wanted to throw this out there for later consideration--what are
the cases where we can extend component behavior without subclassing.
I imagine there will be conflicts if the native behavior conflicts
with the wrapping behavior (if the two are trying to set different
borders, in this case), but interesting in any case.


To unsubscribe, e-mail:
For additional commands, e-mail: