# Popup Screen location

**URL:** <https://forum.inductiveautomation.com/t/popup-screen-location/6358>\
**Category:** Ignition\
**Created:** [May 1, 2013, 1:52pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358 "2013-05-01T13:52:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bugS](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bugS](https://forum.inductiveautomation.com/u/bugS)\
**Post date:** [May 1, 2013, 1:52pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/1 "2013-05-01T13:52:08Z")

</div>

Hello, I would like to know how to have a popup window displayed near the component that I clicked on the main window.

I’ve read about the event.x and event.y properties but, they seem to give me a position relative to the component that was clicked, not relative to the window the component is on. For example, if I have a component that is 20x20 and is at position 100,100 in the root container, then event.x and event.y will give me a number between 0,0 and 20,20 - depending on where I click in the component, which has nothing to do with where the component is in the root container. The component I’m using is from a template - not sure if that makes it any more difficult. How can I read the components x,y positions within the root container.

Sorry if this has been asked before, I’ve already searched the forum but could not find the answer. Thank you…

---

<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:** [May 1, 2013, 2:52pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/2 "2013-05-01T14:52:59Z")

</div>

You’re right. event.getX() and event.getY() will give coordinates it within the component.

Using event.source.getX() and event.source.getY(), however, will give the location of the component. 😃

Hope this helps!

---

<div class="post-metadata">

**Author:** ![bugS](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bugS](https://forum.inductiveautomation.com/u/bugS)\
**Post date:** [May 1, 2013, 3:04pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/3 "2013-05-01T15:04:38Z")

</div>

Thanks for the help, but that doesn’t work for me. I get the following error message

[code][size=85]Traceback (most recent call last):  
File “event:mouseClicked”, line 11, in   
AttributeError: ‘[com.inductiveautomation.factorypmi.application.com](http://com.inductiveautomation.factorypmi.application.com)’ object has no attribute ‘getx’

```
at org.python.core.PyException.fillInStackTrace(PyException.java:70)
at java.lang.Throwable.<init>(Throwable.java:181)
at java.lang.Exception.<init>(Unknown Source)
at java.lang.RuntimeException.<init>(Unknown Source)
at org.python.core.PyException.<init>(PyException.java:46)
at org.python.core.PyException.<init>(PyException.java:43)
at org.python.core.PyException.<init>(PyException.java:61)
at org.python.core.Py.AttributeError(Py.java:173)
at org.python.core.PyObject.noAttributeError(PyObject.java:930)
at org.python.core.PyObject.object ___getattribute__ (PyObject.java:3692)
at org.python.core.PyObject$object ___getattribute___ exposer. __call__ (Unknown Source)
at org.python.core.Deriveds. __findattr_ex__ (Deriveds.java:59)
at org.python.core.PyObjectDerived. __findattr_ex__ (PyObjectDerived.java:983)
at com.inductiveautomation.factorypmi.application.script.PyComponentWrapper. __findattr_ex__ (PyComponentWrapper.java:101)
at org.python.core.PyObject. __getattr__ (PyObject.java:923)
at org.python.pycode._pyx24.f$0(<event:mouseClicked>:15)
at org.python.pycode._pyx24.call_function(<event:mouseClicked>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:539)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:155)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:266)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at $Proxy16.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

```

Ignition v7.5.4 (b1206)  
Java: Sun Microsystems Inc. 1.6.0\_31  
[/size][/code]

I also tried event.source.x and event.source.y but, I always get a result of 0,0

---

<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:** [May 1, 2013, 3:15pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/4 "2013-05-01T15:15:39Z")

</div>

The X and Y need to be capitalized…

Here is sample code I pasted into the mouseClicked event of a button. It changes the button’s text to display:

- The coordinates of the mouseClicked event
- The location of the button within the container
- The size of the button

EDIT: Clean up after forum migration

```auto
x1=event.getX()
y1=event.getY()
x2=event.source.getX()
y2=event.source.getY()
s=event.source.getSize()
x3=s.width
y3=s.height

event.source.text="<html><center>Component: " + str(x1) + "," + str(y1) + "<br>Container: " + str(x2) + "," + str(y2)+"<br>Size: " + str(x3) + "," + str(y3)

```

Hope this helps!

---

<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:** [May 1, 2013, 3:47pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/5 "2013-05-01T15:47:32Z")

</div>

You can copy this code for the button itself, and paste the code directly into the container. That’s just cool stuff… ![8)](https://us1.discourse-cdn.com/inductiveautomation/original/1X/587d7fe0d6822f36e81815ab06aa7164e9d2e057.gif "Cool")

This button will also give the location on the screen. 🙂 You can then look at the script to see what I did.

EDIT: Clean up after forum migration

```auto
<objects timestamp="Wed May 01 11:45:07 EDT 2013" fpmi.archive.type="components" framework.version="7.2.11.209" fpmi.version="4.2.7.109" >
<arraylist len="1">
	<o cls="com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter">
		<o-c m="setEventSet" s="1;java.beans.EventSetDescriptor">
			<o cls="java.beans.EventSetDescriptor">
				<o-ctor s="5;str;java.lang.Class;[java.beans.MethodDescriptor;java.lang.reflect.Method;java.lang.reflect.Method">
					<str>mouse</str>
					<class>java.awt.event.MouseListener</class>
					<array cls="java.beans.MethodDescriptor" len="5">
						<o id="0" cls="java.beans.MethodDescriptor">
							<o-ctor s="2;java.lang.reflect.Method;[java.beans.ParameterDescriptor">
								<method>java.awt.event.MouseListener|mouseClicked|1;java.awt.event.MouseEvent</method>
								<null/>
							</o-ctor>
						</o>
						<o cls="java.beans.MethodDescriptor">
							<o-ctor s="2;java.lang.reflect.Method;[java.beans.ParameterDescriptor">
								<method>java.awt.event.MouseListener|mouseEntered|1;java.awt.event.MouseEvent</method>
								<null/>
							</o-ctor>
						</o>
						<o cls="java.beans.MethodDescriptor">
							<o-ctor s="2;java.lang.reflect.Method;[java.beans.ParameterDescriptor">
								<method>java.awt.event.MouseListener|mouseExited|1;java.awt.event.MouseEvent</method>
								<null/>
							</o-ctor>
						</o>
						<o cls="java.beans.MethodDescriptor">
							<o-ctor s="2;java.lang.reflect.Method;[java.beans.ParameterDescriptor">
								<method>java.awt.event.MouseListener|mousePressed|1;java.awt.event.MouseEvent</method>
								<null/>
							</o-ctor>
						</o>
						<o cls="java.beans.MethodDescriptor">
							<o-ctor s="2;java.lang.reflect.Method;[java.beans.ParameterDescriptor">
								<method>java.awt.event.MouseListener|mouseReleased|1;java.awt.event.MouseEvent</method>
								<null/>
							</o-ctor>
						</o>
					</array>
					<method>java.awt.Component|addMouseListener|1;java.awt.event.MouseListener</method>
					<method>java.awt.Component|removeMouseListener|1;java.awt.event.MouseListener</method>
				</o-ctor>
			</o>
		</o-c>
		<o-c m="setJythonCode" s="1;str"><str># This script was generated automatically by the tag set
# script builder. You may modify this script, but if you do,
# you will not be able to use the tag set builder to update
# this script without overwriting your changes.

x1=event.getX()
y1=event.getY()
x2=event.source.getX()
y2=event.source.getY()
x3=event.source.getLocationOnScreen().x
y3=event.source.getLocationOnScreen().y
w1=event.source.getSize().width
h1=event.source.getSize().height

event.source.text=&quot;&lt;html&gt;&lt;center&gt;Click in Comp.: &quot; + str(x1) + &quot;,&quot; + str(y1) + &quot;&lt;br&gt;Container Loc.: &quot; + str(x2) + &quot;,&quot; + str(y2) +&quot;&lt;br&gt;Screen Loc.: &quot; + str(x3) + &quot;,&quot; + str(y3) +&quot;&lt;br&gt;Size: &quot; + str(w1) + &quot;,&quot; + str(h1)</str></o-c>
		<o-c m="setMethodDescriptor" s="1;java.beans.MethodDescriptor"><ref>0</ref></o-c>
		<o-c m="setTarget" s="1;java.awt.Component">
			<c id="1" cls="com.inductiveautomation.factorypmi.application.components.PMIButton">
				<c-comm>
					<dim>279;78</dim>
					<rect>158;113;279;78</rect>
					<str>Button</str>
					<lc>158;113;16;0;0.043010753;0.15384616</lc>
				</c-comm>
				<c-c m="setText" s="1;str"><str>&lt;html&gt;&lt;center&gt;Click in Comp.: 236,49&lt;br&gt;Container Loc.: 15,20&lt;br&gt;Screen Loc.: 544,212&lt;br&gt;Size: 279,78</str></c-c>
			</c>
		</o-c>
	</o>
</arraylist>
<ref>1</ref>
</objects>

```

---

<div class="post-metadata">

**Author:** ![bugS](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bugS](https://forum.inductiveautomation.com/u/bugS)\
**Post date:** [May 1, 2013, 5:40pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/6 "2013-05-01T17:40:52Z")

</div>

JordanCClark - thanks works perfect. I guess the method I was looking for is “.getLocationOnScreen().x”

I really did search Google, forums and Ignition help, to find this type of function but to no avail. Can you point me to a better way to search for these kinds of “hidden” methods/properties - so I can solve my own problems in the future?

---

<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:** [May 1, 2013, 6:50pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/7 "2013-05-01T18:50:50Z")

</div>

Well, I’ll admit it’s sometimes a TIAS (Try It And See) method of programming. I certainly didn’t get it on the first try. I’m not necessarily the best programmer here, I’m just more tenacious than most! 😆

What I can tell you is that things relating to components are all Java Swing methods, so you can learn a bit through the javadocs.

Google can really be your friend. A search may go something like “java swing find location of a component”.

Some of my inspirations comes from the StackOverflow site, but a lot is from others’ posts here on the forum that will jog something in the back of by brain.

Wish I could have a better answer for you. In the meantime, don’t be afraid to post questions here on the forum. We have a great group of people here ready to lend a hand. ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![dbrucejohnson](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dbrucejohnson](https://forum.inductiveautomation.com/u/dbrucejohnson)\
**Post date:** [April 17, 2019, 3:53pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/8 "2019-04-17T15:53:52Z")

</div>

Here is the code you are looking for:

container\_X = event.source.getLocationOnScreen().x  
container\_Y = event.source.getLocationOnScreen().y

window\_X = system.gui.getParentWindow(event).getLocationOnScreen().x  
window\_Y = system.gui.getParentWindow(event).getLocationOnScreen().y

source\_relX = container\_X - window\_X + event.source.relX  
source\_relY = container\_Y - window\_Y + event.source.relY

print source\_relX  
print source\_relY

system.gui.transform(system.gui.getParentWindow(event).getRootContainer().getComponent(‘Rectangle’),source\_relX + event.source.relWidth, source\_relY)

---

<div class="post-metadata">

**Author:** ![dbrucejohnson](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dbrucejohnson](https://forum.inductiveautomation.com/u/dbrucejohnson)\
**Post date:** [April 17, 2019, 4:03pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/9 "2019-04-17T16:03:44Z")

</div>

Create 2 Rectangles (Rectangle1, Rectangle2)  
Put Rectangle2 on the Root Container  
Put Rectangle1 anywhere, in a container or container in a container 3 deep…

Copy this code to Rectangle 1 mouseClicked Event Handler:

container\_X = event.source.getLocationOnScreen().x  
container\_Y = event.source.getLocationOnScreen().y

window\_X = system.gui.getParentWindow(event).getLocationOnScreen().x  
window\_Y = system.gui.getParentWindow(event).getLocationOnScreen().y

source\_relX = container\_X - window\_X + event.source.relX  
source\_relY = container\_Y - window\_Y + event.source.relY

print source\_relX  
print source\_relY

This code will move Rectangle2 next to Rectangle1 no mater where it is!

system.gui.transform(system.gui.getParentWindow(event).getRootContainer().getComponent(‘Rectangle2’),source\_relX + event.source.relWidth, source\_relY)

---

<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:** [April 17, 2019, 4:10pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/10 "2019-04-17T16:10:29Z")

</div>

Don’t forget to enclose your code in triple backquotes ( ``` ), my friend. 🙂

---

<div class="post-metadata">

**Author:** ![dbrucejohnson](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dbrucejohnson](https://forum.inductiveautomation.com/u/dbrucejohnson)\
**Post date:** [April 17, 2019, 4:18pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/11 "2019-04-17T16:18:43Z")

</div>

Hi Jordan,  
Why enclose code in triple backquotes ( ``` )?  
Bruce

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2019, 4:47pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/12 "2019-04-17T16:47:14Z")

</div>

> [@dbrucejohnson](#):
>
> Why enclose code in triple backquotes

To cause the forum's code-formatter to make it readable for the rest of us. Place them on lines by themselves above and below your code. More information here:

> **[Select the programming language used in code blocks](https://meta.discourse.org/t/select-the-programming-language-used-in-code-blocks/19247)**
>
> When using triple backticks to enclose code blocks, Discourse will attempt to autodetect the language using highlight.js. If this does not do what you expect, you can type a language name after the first set of backticks: E.g. \`\`\` ruby 3.times...

---

<div class="post-metadata">

**Author:** ![dbrucejohnson](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dbrucejohnson](https://forum.inductiveautomation.com/u/dbrucejohnson)\
**Post date:** [April 17, 2019, 4:51pm UTC](https://forum.inductiveautomation.com/t/popup-screen-location/6358/13 "2019-04-17T16:51:40Z")

</div>

Thanks for the clarity!
