# Move Popup Within Bounds of Client Window

**URL:** <https://forum.inductiveautomation.com/t/move-popup-within-bounds-of-client-window/87865>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [March 25, 2024, 8:43pm UTC](https://forum.inductiveautomation.com/t/move-popup-within-bounds-of-client-window/87865 "2024-03-25T20:43:52Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 27, 2024, 1:03pm UTC](https://forum.inductiveautomation.com/t/move-popup-within-bounds-of-client-window/87865/7 "2024-03-27T13:03:50Z")

</div>

There we go! I replaced it in the `setLocation` call, but nowhere else. That's perfect.

```python
# Import the necessary Javax Swing classes
from javax.swing import JFrame,SwingUtilities

def moveWindowRelative(window):
	'''
		Moves a popup window to a position
	'''
	
	
	# Find the nearest ancestor JFrame of the window component which will be the parent window that the popup was opened from
	parentJFrame = SwingUtilities.getAncestorOfClass(JFrame, window)
	
	# Set a margin value for positioning the window
	parentJFrameMargin = 30
	#initially assume a window move is required
	moveRequired = True
	
	# Try to get the mouse position relative to the parent JFrame
	try:
	    windowX = parentJFrame.getMousePosition(True).x
	    windowY = parentJFrame.getMousePosition(True).y

	# If an exception occurs (e.g., mouse position not available), do not move the window
	except:
		moveRequired = False
		
	if moveRequired:
	
		# Ensure that the window is within the boundaries of the parent JFrame
		if windowX < parentJFrameMargin:
		    windowX = parentJFrameMargin
		elif windowX + window.width > parentJFrame.width - parentJFrameMargin:
		    windowX = parentJFrame.width - window.width - parentJFrameMargin
		if windowY < parentJFrameMargin:
		    windowY = parentJFrameMargin
		elif windowY + window.height > parentJFrame.height - parentJFrameMargin:
		    windowY = parentJFrame.height - window.height - parentJFrameMargin 
		
		# Set the new location of the window based on the calculated positions
		window.setLocation(windowX, windowY)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/move-popup-within-bounds-of-client-window/87865)._
