Max Window size in different monitors

I want to use a button to change the window to full size. The challenge is that this full size is different for some monitor.
I would like that the option “start maximized” be re launchable or something.

I found

But I don’t understand how to make it work. Please some help

You can get all your screen sizes with code like @Carl.Gould suggests in the other thread you posted in:

from java.awt import GraphicsEnvironment

env = GraphicsEnvironment.getLocalGraphicsEnvironment()
for i, screen in enumerate(env.getScreenDevices()):
	size = screen.getDefaultConfiguration().bounds
	print "Screen %i is %dx%d" % (i, size.width, size.height)

Output when tested in script console with a couple monitors:

>>> 
Screen 0 is 1366x768
Screen 1 is 1920x1080
>>> 

Do you mean full screen mode where the window fills the whole screen with no title bar? If so, the code below on a button will swap the desktop the button is contained in between full screen and windowed modes.

from javax.swing import JFrame

window = system.gui.getParentWindow(event)
while not isinstance(window, JFrame):
	window = window.getParent()
if window.isUndecorated():
	# Switch to windowed mode.
	window.dispose()
	window.setUndecorated(False)
	window.setExtendedState(JFrame.NORMAL)
	# Restore previous window size and location, if available.
	try:
		normalW = event.source.getClientProperty('normalW')
		normalH = event.source.getClientProperty('normalH')
		normalX = event.source.getClientProperty('normalX')
		normalY = event.source.getClientProperty('normalY')
		window.setSize(normalW, normalH)
		window.setLocation(normalX, normalY)
	except:
		pass
	window.setVisible(True)
else:
	# Store window size and location for restore.
	event.source.putClientProperty('normalW', window.size.width)
	event.source.putClientProperty('normalH', window.size.height)
	event.source.putClientProperty('normalX', window.x)
	event.source.putClientProperty('normalY', window.y)
	# Switch to full screen mode.
	window.dispose()
	window.setUndecorated(True)
	window.setExtendedState(JFrame.MAXIMIZED_BOTH)
	window.setVisible(True)
1 Like

It’s so awesome how this code works smoothy.
Sir thanks so much. This gives me a lot to work with.

If possible, I wish you can help me to learn more about coding

1 Like

Ignition is built on Java, so the above is accomplished by working with the underlying Java. Little of the script is Ignition scripting functions, but you’ll find documentation on the window actions by searching the internet for “JFrame”, the Java component that contains an Ignition desktop.

This script works great, I am using it to switch a project to window mode so it can be moved to an external monitor.

When I press the button again for it to go back to full screen mode, it moves back to the original monitor.

Is there a way to make it full screen on the monitor it is moved to?

Thank you.

I just tried dragging a window between monitors and then running this script from a button and it does go full screen on the monitor it is on. Could it be that it’s between monitors–partly on both–when you’re seeing it return to the original monitor on switch to full screen?

It appears that it’s only on the monitor I dragged it too. I’ll look if there’s something set up in my display settings.