# Template Canvas Help

**URL:** <https://forum.inductiveautomation.com/t/template-canvas-help/30671>\
**Category:** Ignition\
**Created:** [December 12, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/template-canvas-help/30671 "2019-12-12T19:19:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanastiefes](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ryanastiefes](https://forum.inductiveautomation.com/u/ryanastiefes)\
**Post date:** [December 12, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/template-canvas-help/30671/1 "2019-12-12T19:19:59Z")

</div>

7.8.5

Reaching out to anyone that might shed some light on my project. I currently have a custom SVG of a map that is set on a Template Canvas in which I am changing the map dimensions by way of a mouse scroll using the MouseWheelListener() in the event handler of the main screen using the internalFrameActivated.

```auto
from javax.swing import SwingUtilities
from javax.swing import JScrollPane
from java.awt.event import MouseWheelEvent
from java.awt.event import MouseWheelListener

class DebugMouseWheelListener(MouseWheelListener):
	def mouseWheelMoved(self, event):
		mouse = event.getWheelRotation()
		if mouse == 1 and event.isControlDown():
			system.tag.write("District Map Tags/Map Width",1500)
			system.tag.write("District Map Tags/Map Height",1200)
		elif mouse == -1 and event.isControlDown():
			system.tag.write("District Map Tags/Map Width",3500)
			system.tag.write("District Map Tags/Map Height",3000)
			
			

event.source.rootContainer.addMouseWheelListener(DebugMouseWheelListener())

scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, system.gui.getParentWindow(event).getComponentForPath('Root Container.Template Canvas').getComponents()[2].getComponents()[0])

scrollPane.getVerticalScrollBar().setUnitIncrement(300) #scroll amount for wheel and arrows
scrollPane.getVerticalScrollBar().setBlockIncrement(300) #scroll amount clicking on scrollbar itself
scrollPane.getHorizontalScrollBar().setUnitIncrement(300) 
scrollPane.getHorizontalScrollBar().setBlockIncrement(300) 

system.gui.getParentWindow(event).getComponentForPath('Root Container.Template Canvas').templates

```

I have two questions and am still a noob on this scripting stuff:

1. My MouseWheelListener only works on the rootContainer due to my script below, I want this to work when my cursor is on the Template Canvas. Would I add in a getComponent("Template Canvas’) before the addMouseWheelListener, I tried .rootContainer.templateCanvas but it didnt work.

`event.source.rootContainer.addMouseWheelListener(DebugMouseWheelListener())`

1. My client is larger than my viewpoint, How do I set where the JViewport starts. [“I’m currently reading this”](https://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html)

This is my default start:

 ![Client](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c159f440d0c057577cd9fd8f5d18a535044663ac.png)

I would like this to be my default start or even dynamically set the JViewport based on my cursor screen coordinates.

 ![ClientCenterLarge](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6b422bfcbd78ca050174b1a1f3be8c332cd74942.png)

Any thoughts or advice of where I should be looking is much appreciated. Thanks

---

<div class="post-metadata">

**Author:** ![pdc5067](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pdc5067](https://forum.inductiveautomation.com/u/pdc5067)\
**Post date:** [February 1, 2021, 5:02pm UTC](https://forum.inductiveautomation.com/t/template-canvas-help/30671/2 "2021-02-01T17:02:34Z")

</div>

I am trying to figure out the same thing. I have a layout and when I specify a certain portion of my layout via a dropdown component, I want to set the JViewport to that area of the layout. Did you ever figure this out? I am very very new to java and cant figure out how to set it. I am running my current code in the initialize template script.
