Why Does a Popup Window Zoom or Misalign at Runtime?

James Nishida7 min read
HMI ProgrammingOther ManufacturerTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Popup window scaling and right-edge misalignment usually come from mixing designer dimensions, runtime dimensions, and screen coordinates. Before anything else, confirm the popup trigger, identify the actual parent window, and measure the runtime container bounds. The subtraction 2520 - 255 = 2265 is correct only when 2520 is the runtime width and both values use the same coordinate origin.

Commissioning decision path

  1. Set the button's Navigation action to No Action. Open the popup only from the button's actionPerformed script. Confirm that one popup opens per click before continuing.
  2. Check the popup's designer x and y parameters. Set both to 0. Confirm that no stored designer offset remains.
  3. Retrieve the event's parent window and print its path. Confirm that the path identifies the intended main window. If it identifies a docked or other window, switch to an explicit main-window lookup.
  4. Read the main window or root container's runtime width and screen location. Do not use the designer width until it matches the runtime reading.
  5. Temporarily set the popup height to 500. Open and position it again. If zooming stops, the normal popup height is overflowing the runtime bounds during opening.
  6. Calculate the popup position from one coordinate system. For screen positioning, add the parent or root container's screen origin to its runtime width, then subtract the popup width.
  7. Restore the required height only after the smaller popup opens correctly. Resize it dynamically from the runtime parent height, then repeat the alignment and scaling checks.
Observed result Reading to take Likely cause Next check
Popup lands too far right Parent screen X, runtime width, popup width A screen coordinate is being calculated as though the parent began at X = 0 Use the root container's screen origin
Popup aligns to the wrong window parentWindow.path The event parent is a docked or nested window Retrieve the intended window by name
Whole display appears zoomed Runtime parent height and popup height The popup opens outside the usable runtime bounds Test with popup height 500
Position changes after resizing Popup width before and after resize The X coordinate was calculated from a stale width Recalculate X after any width change

Popup trigger configuration

Do not combine a configured Navigation action with an actionPerformed script that also calls system.nav.openWindow. Two navigation paths make the opening sequence and final window reference difficult to diagnose.

  1. Open the button's Navigation tab.
  2. Change the action to No Action.
  3. Open the Script Editor and place the popup-opening logic in the button's actionPerformed event.
  4. Click the button once and confirm that the returned popup object is the window being moved.
# Get the parent window
parentWindow = system.gui.getParentWindow(event)

# Open the popup
popup = system.nav.openWindow('CM/Popup')

This creates a defined sequence: retrieve the window associated with the event, open CM/Popup, calculate its coordinates, and move it. Do not move on until the popup is opened by this script alone.

Parent-window identity

A button can belong to a docked window, tabbed area, or nested window rather than the visual main window used as the alignment reference. Test that relationship instead of inferring it from the display.

  1. Open Tools-->Console.
  2. Clear the existing console output.
  3. Run the following code from the button's actionPerformed handler.
  4. Read the printed path and compare it with the intended main window.
parentWindow = system.gui.getParentWindow(event)
print 'Parent Window Path: ', parentWindow.path

If the printed path is the intended main window, continue with its runtime bounds. If the button retrieves another window, reference the main window explicitly:

mainWindow = system.gui.getWindow('Window Name')

One installation used system.gui.getWindow('L4/4_1_0_lijn4_Productielijn') to select the required main window directly. Use the actual window name from the project; the example path is not a universal setting.

Coordinate-system selection

The expression parentWindow.width - popup.width calculates an X offset relative to the parent's left edge. It does not include the parent's screen position. That result works only when popup.setLocation(x, y) is being supplied coordinates with the same origin and the relevant parent begins at X = 0.

For a popup width of 255 and a reference width of 2520, the arithmetic gives:

x = 2520 - 255
x = 2265

The value 2265 represents a right-aligned local offset. If the reference content begins at a nonzero screen X coordinate, add that origin:

right_aligned_screen_x = reference_screen_x + reference_width - popup_width

Use the root container when docked windows, borders, or surrounding client layout shift the usable content away from the outer window origin:

mainWindow = system.gui.getWindow('Window Name')
container = mainWindow.getRootContainer()
origin = container.getLocationOnScreen()

x = origin.x + container.width - popup.width
y = origin.y
popup.setLocation(x, y)

This aligns the popup's right edge with the root container's right edge and its top with the container's screen Y coordinate. A fixed value such as y = 103 may match one layout, but it does not track changes in the window's screen position. Confirm alignment using runtime origins rather than compensating with arbitrary offsets.

Runtime bounds and scaling check

Designer size is not automatically the size available in a running session. Window decoration, docked content, client layout, and runtime display dimensions can reduce or offset the usable area. A popup sized precisely against designer dimensions can therefore cross the runtime boundary when it opens.

Test the overflow branch with one controlled change:

  1. Keep the popup designer x and y values at 0.
  2. Temporarily change its height from 1190 to 500.
  3. Open it using the script-only trigger.
  4. Position it from the verified parent or root-container runtime dimensions.
  5. Observe whether the whole-screen zooming disappears.

If the 500-high popup opens without zooming, the normal height is the deciding variable. Opening an oversized or over-positioned popup can expand the effective bounds and cause the main content to scale to accommodate them. The corrective sequence is to open the popup at a size that fits, then apply the session-derived height.

If zooming remains with height 500, return to the parent-path and coordinate-origin checks. The result then points away from height overflow and toward selection of the wrong reference window or mixing local and screen coordinates.

Dynamic height and right-edge placement

When the popup must match the parent window's session height, read that height at runtime and apply it with a Java Dimension. The supplied method changes height while retaining the popup's current width:

from java.awt import Dimension

# Get the parent window
parentWindow = system.gui.getParentWindow(event)

# Read runtime dimensions
parentWidth = parentWindow.width
parentHeight = parentWindow.height

# Open the popup
popup = system.nav.openWindow('CM/Popup')

# Calculate local right-edge coordinates
x = parentWidth - popup.width
y = 0

# Position and resize
popup.setLocation(x, y)
popup.setPreferredSize(Dimension(popup.width, parentHeight))
popup.setSize(Dimension(popup.width, parentHeight))

Use this local-coordinate form only after confirming that the popup location and parent dimensions share the same origin. Where the popup requires screen coordinates, combine the runtime resize with the root-container origin:

from java.awt import Dimension

mainWindow = system.gui.getWindow('Window Name')
container = mainWindow.getRootContainer()
origin = container.getLocationOnScreen()

popup = system.nav.openWindow('CM/Popup')

popup.setPreferredSize(Dimension(popup.width, container.height))
popup.setSize(Dimension(popup.width, container.height))

x = origin.x + container.width - popup.width
y = origin.y
popup.setLocation(x, y)

Setting both preferred size and current size addresses layout preference and the live window dimensions. If the required height triggers scaling during the initial open, keep the popup smaller in the designer, open it, and then run the resize operations. Do not change the popup width without recalculating x, because right-edge alignment depends directly on the final width.

Resolving-branch verification

  1. Confirm the Navigation tab remains set to No Action and that one button click opens one instance of CM/Popup.
  2. Confirm the console prints the intended parentWindow.path, or verify that system.gui.getWindow('Window Name') returns the selected main window.
  3. Record the root container's screen X and Y coordinates, runtime width, and runtime height. Confirm that the calculation uses those live values.
  4. Verify horizontal placement using the edge equation: popup X + popup width = container screen X + container width.
  5. Verify top placement using popup Y = container screen Y, unless the design calls for a deliberate vertical offset.
  6. Run the popup first at height 500. Confirm that the main content does not zoom.
  7. Apply the runtime container height with setPreferredSize and setSize. Confirm that the popup remains within the intended bounds and its right edge stays aligned.
  8. Repeat the test after navigating between the relevant main and docked windows. Confirm that the printed parent path, calculated origin, popup location, and display scale remain correct on every opening.

FAQ

What happens if I calculate X as 2520 minus 255?

The result is 2265, but it is only a local right-edge offset. For screen positioning, calculate reference screen X + 2520 - 255 using the actual runtime width in place of 2520.

What happens if the popup height exceeds the runtime window?

The popup can expand the effective bounds and make the main display appear scaled or zoomed. Test with height 500; if scaling stops, open at the smaller size and resize to the measured runtime height afterward.

What happens if the button belongs to a docked window?

system.gui.getParentWindow(event) may return the docked window rather than the desired main window. Print parentWindow.path, select the main window explicitly when needed, and complete the final check that the popup's right edge equals the root container's screen X plus its runtime width.

Back to blog