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…
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
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?
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.
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:
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: