The way your code is written, subEvent.source
and event.source
are the same thing, but subEvent.source
will fail when calling a custom method because of the reason I listed above; the component loses its wrapper when referenced from the custom listener.
The most common place I encounter this issue is when I obtain a component using SwingUtilities.getAncestorOfClass
instead of using a recursive function. See this forum post for reference:
Why can't custom properties and methods be accest from a component that is obtained using SwingUtilities.getAncestorOfClass
Agreed.