Modal windows

I know this is a really old thread now, but if anyone else stumbles across it like I did looking for a solution, here’s what I did:
(WARNING: it’s a bit of a messy hack, but worked for me)

def showModal(windowPath, params=None):
	from javax.swing import JDialog
	window = system.nav.openWindowInstance(windowPath, params)
	rc = window.getRootContainer()
	cp = window.getContentPane()
	window.setVisible(False)
	dlg = JDialog(None, True)
	dlg.setContentPane(cp)
	dlg.setMinimumSize(window.getMinimumSize())
	dlg.setMaximumSize(window.getMaximumSize())
	dlg.setSize(window.getWidth(), window.getHeight())
	dlg.setTitle(window.getTitle())
	dlg.setLocationRelativeTo(None)
	dlg.setVisible(True)
	system.nav.closeWindow(window)
	return rc.Result

The root container should have a custom property called “Result” whose value is set, e.g. from a input text field, etc.

If the window has a ‘Close’ button etc on it, I had to define and call the following function to make it work as a modal dialog:

def close(event):
	try:
		system.nav.closeParentWindow(event)
	except:
		from javax.swing import SwingUtilities
		from java.awt.event import WindowEvent
		frame = SwingUtilities.getWindowAncestor(event.source)
		frame.dispatchEvent(WindowEvent(frame, WindowEvent.WINDOW_CLOSING))
3 Likes