# Button template

**URL:** <https://forum.inductiveautomation.com/t/button-template/62812>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [August 9, 2022, 6:58am UTC](https://forum.inductiveautomation.com/t/button-template/62812 "2022-08-09T06:58:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [August 9, 2022, 6:58am UTC](https://forum.inductiveautomation.com/t/button-template/62812/1 "2022-08-09T06:58:09Z")

</div>

Hello,

I’m simply trying to make a button template so I have the same type of button everywhere in my project, so if I change the color it changes every button

The problem is, when I try to make a mouseClicked event on an instance of the template, it doesn’t work because when you click the instance, the event called is the event of the button from inside the template

Every button could do a different action, like system.nav.swapTo or set a tag to a value or set multiple tags to different values, etc.

I tried this :

 ![ButtonTemplate](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/b/fbbf0ac8fe61421eadfc93e6b50aeafca5cabed3.png)

I got the instance that is called “btnTest” and tried to call the event “mouseClicked” but nothing works

This is my instance :

 ![ButtonInstance](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/d/6de94ffa0dab3e7e377644f574eb6cb8c4093019.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 9, 2022, 11:38am UTC](https://forum.inductiveautomation.com/t/button-template/62812/2 "2022-08-09T11:38:44Z")

</div>

I would recommend, instead of using a template, is to bind the colors to tags. After you get it the way you want it, you can add it to a custom palette.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/8/7802aa43fbf4d086fcb9a5626e85a8f8b2785c9a.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2ece10813f87613a588bca0bf5c177187ab2850f.png)

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [August 9, 2022, 1:18pm UTC](https://forum.inductiveautomation.com/t/button-template/62812/3 "2022-08-09T13:18:55Z")

</div>

With the template I can change everything, color, text, font, size, etc, even change de design  
With the palette and binding it would demand a lot of tags

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 9, 2022, 3:26pm UTC](https://forum.inductiveautomation.com/t/button-template/62812/4 "2022-08-09T15:26:52Z")

</div>

Bind them to the _ **same tags** _ for color.

Example coming.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [August 9, 2022, 4:06pm UTC](https://forum.inductiveautomation.com/t/button-template/62812/5 "2022-08-09T16:06:54Z")

</div>

> [@David\_Gonzalez](#):
>
> The problem is, when I try to make a mouseClicked event on an instance of the template, it doesn’t work because when you click the instance, the event called is the event of the button from inside the template

Put this inside the event you want to handle for your instances. We used mousePressed for our templates:

```auto
from javax.swing import SwingUtilities
template = event.source.parent.parent
convertedEvent = SwingUtilities.convertMouseEvent(event.source,event,template)
template.dispatchEvent(convertedEvent)

```

This code should be put on the template definition not the template instance FYI

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 9, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/button-template/62812/6 "2022-08-09T16:26:07Z")

</div>

[ButtonStyle\_2022-08-09\_1222.zip](https://forum.inductiveautomation.com/uploads/short-url/x6vt025ZO2gXz3u1QPx1Lr6kBBW.zip) (8.8 KB)

Example has a button with a custom property called ‘style’. Colors are set through the style customizer of the button driven by the ‘style’ custom property. the value of ‘style’ is set via different mouse events of the button. The dataset for the styles is bound to a client tag.

[https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/6/76c159f9bbf52692805f0e0c82c9a8fd267eea8d.mp4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/6/76c159f9bbf52692805f0e0c82c9a8fd267eea8d.mp4)

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [August 10, 2022, 5:59am UTC](https://forum.inductiveautomation.com/t/button-template/62812/7 "2022-08-10T05:59:31Z")

</div>

Thanks! I could use it for other projects

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [August 10, 2022, 6:03am UTC](https://forum.inductiveautomation.com/t/button-template/62812/8 "2022-08-10T06:03:58Z")

</div>

I found the solution

So if the instance has a script in mouseClicked, the button inside the template should have this script in mouseClicked:

` 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)`
