Button Events Within Templates

Here is how I do it.

from java.awt.event import MouseEvent
evt = MouseEvent(event.source.parent.parent,event.getID(),event.getWhen(),event.getModifiers(),event.x,event.y,event.clickCount,event.popupTrigger,event.button)
event.source.parent.parent.dispatchEvent(evt)

We take the originating event, from a label inside the template, and create a new instance of the mouse event, only changing the source. If we do not do this, then event.source will be equal to the triggering component inside the template, not the template itself. We then move up the component tree, where event.source.parent is the template itself, and event.source.parent.parent is the TemplateHolder, which is the template when it is placed on a screen. This will then fire the mouseEvent properties on the template instance itself, so you can have a template for your styling, but have the actions defined per instance.

Enclosed is an example button as well.

demo_nav_button_2018-04-27_1217.proj (6.5 KB)

12 Likes