Popup Windows Debugging

Can you only debug the Popup windows from the client.

Meaning while in designer, I can't get my popup window to popup to a Static Location, it always popups up at location 0 , 0 . And I do have that programmed in the popup windows setting and I also have the "And Center" unchecked in my scripting feature.

Correct. The designer will open an editor for the popup window, not an actual pop-up window instance.

1 Like

I'm still having trouble with Popups. I can't get them to start at a STATIC LOCATION, even with the "And Center" un-checked in the scripting function of my button.
My button will cause the popup to display but it alway starts at 0,0 location.

Those are the two choices. 0,0 or centered. You will need to move the window after opening it if you want it elsewhere. Have you tried setting winObj.x and winObj.y to your desired coordinates?

I use the internal frame opened event handler to move popup Windows to specific positions. The move happens so fast that the window appears to have opened in that location. I don't believe that the GUI actually paints the window at the original open location.

I'm sorry but I'm at a lost here.
I have a window that has a button on it, I want the button to open a popup window at a specific location.
Can you provide an example?

I'm using version 7.9.10

Hmmm. Actually, you would use .setLocation(). Standard java.swing JFrame method.

popup = system.nav.openWindow("path/to/window", {'someParam': 'paramValue'})
popup.setLocation(200, 50)

(A component's or window's .x and .y properties are read-only.)

1 Like

Note that @pturmel's script would run from the button's actionPerformed event handler. If you use the internalFrameOpened event handler as I suggested, your code will look something like this:

locationX = 100
locationY = 100
window = event.source
window.setLocation(locationX, locationY)

Edit:
I prefer this approach because, for obvious reasons, my navigation buttons are typically templates, and since not all popups are doing the same thing, it's not practical to make the locationX and locationY calculations generic.

Subsequent Edit:
Changed window = system.gui.getParentWindow(event) to window = event.source per @pturmel 's recommendation

I don't like that approach because it precludes allowing the caller to determine the best location--typically related to the caller's position. This is especially useful when opening multiple of the same popup using .openWindowInstance().

{ Also, a window event's event object's .source is the window. No need to call .getParentWindow() in those. }

I often run multi monitor instances of the same session, and some of my popups are triggered off of mouse location, so if I'm not mistaken, this is the reason my code requires getParentWindow()

That doesn't make any sense. Please explain why this matters for a window's own internalFrameOpened event.

I really appreciate all of the information, this really helps.

1 Like

Hmm. It's been some time since I developed the script that I parsed that example from, so I don't remember all of the problems I had to solve creating this. This particular popup can be launched from a keyboard shortcut that is gateway scoped or from a right click on an information icon that is on every desktop. The environment that this popup lives in involves FIVE desktop instances. The popup position appears up and to the left of the mouse cursor, unless this creates an out of bounds condition for the window it lives in.
Here is the positioning code in its entirety. The data gathering aspects of the code have been sanitized to make the example concise and relevant. I welcome your feedback and refactoring ideas because I am as hungry for knowledge as anyone who routinely reads this forum:

import java.awt.MouseInfo
from javax.swing import JFrame,SwingUtilities
window = system.gui.getParentWindow(event)
myFrame = SwingUtilities.getAncestorOfClass(JFrame,window)
intDesktopWidth = myFrame.getWidth()
intDesktopHeight = myFrame.getHeight()
intDesktopX = myFrame.getLocation().x
intDesktopY = myFrame.getLocation().y
windowX = java.awt.MouseInfo.getPointerInfo().getLocation().x-320-intDesktopX
windowY = java.awt.MouseInfo.getPointerInfo().getLocation().y-intDesktopY
#Omitted Code
#The code that has been omitted here creates a dataset for a power table that comprises the body of the popup window
#minimumHeight = finalizedDataset.getRowCount()
minimumHeight = 10 #this line added to replace the necessary minimumHeight result that is created by the ommitted code
if minimumHeight > 20:
	minimumHeight = 20
windowHeight = 50+(minimumHeight*25)
window.getComponentForPath('_parent').size = (306, windowHeight)
windowY = windowY - windowHeight - 100
if windowX > 0:
	if windowY > 0:
		if windowX + 306 < intDesktopWidth:
			if windowY + windowHeight < intDesktopHeight:
				window.setLocation(windowX, windowY)
else:
	window.setLocation(10, 10)

Edit: I do remember this:
In this example the mouse cursor position is always relative to screen (0,0) and not desktop (0,0), so some hocus pocus is necessary to find out where the desktop is relative to the mouse cursor position.

This:

Can be replaced with this:

window = event.source

within any window events. Regardless how complex the rest of the script is. (Oh--I think swing has helpers for those coordinate calculations, too.)

1 Like

Confirmed. I've changed my code accordingly

@pturmel
I just wanted to let you know that I took your hint and cleaned up my original code using the swing utilities. Here is the refactored code:

from javax.swing import JFrame,SwingUtilities
window = event.source
myFrame = SwingUtilities.getAncestorOfClass(JFrame,window)
intDesktopWidth = myFrame.getWidth()
intDesktopHeight = myFrame.getHeight()
try:
	windowX = myFrame.getMousePosition(True).x - window.width
	windowY = myFrame.getMousePosition(True).y
except:
	windowX = 0
	windowY = 0
#Omitted Code
#The code that has been omitted here creates a dataset for a power table that comprises the body of the popup window
#minimumHeight = finalizedDataset.getRowCount()
minimumHeight = 10 #this line added to replace the necessary minimumHeight result that is created by the ommitted code
if minimumHeight > 20:
	minimumHeight = 20
windowHeight = 50+(minimumHeight*25)
window.size.height = windowHeight
windowY = windowY - windowHeight - 100
if windowX <= 0:
	windowX = 10
if  windowY <= 0:
	windowY = 10
window.setLocation(windowX, windowY)

If you see anything else that can be improved, please let me know, and thanks again for taking the time to correct my perceptual error.

1 Like