# Max Window size in different monitors

**URL:** <https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [February 7, 2020, 4:59am UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030 "2020-02-07T04:59:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 7, 2020, 4:59am UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/1 "2020-02-07T04:59:48Z")

</div>

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

> [@Determining window size](https://forum.inductiveautomation.com/t/determining-window-size/2525/5):
>
> [code]from java.awt import GraphicsEnvironment
> 
> env = GraphicsEnvironment.getLocalGraphicsEnvironment()  
> screen = env.getDefaultScreenDevice()  
> size = screen.getDefaultConfiguration().bounds  
> print “The main screen is %dx%d” % (size.width, size.height)[/code]
> 
> You can get the screen size of any other monitors too by looping through the results of [tt]env.getScreenDevices()[/tt]

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

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 7, 2020, 6:19am UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/2 "2020-02-07T06:19:26Z")

</div>

You can get all your screen sizes with code like @Carl.Gould suggests in the [other thread you posted in](http://forum.inductiveautomation.com/t/determining-window-size/2525):

```python
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:

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

```

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 7, 2020, 7:41am UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/3 "2020-02-07T07:41:38Z")

</div>

> [@jespinmartin1](#):
>
> I want to use a button to change the window to full size.

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.

```python
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)

```

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 7, 2020, 1:29pm UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/4 "2020-02-07T13:29:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 7, 2020, 5:16pm UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/5 "2020-02-07T17:16:58Z")

</div>

Ignition is built on Java, so the above is accomplished by working with the underlying Java. Little of the script is [Ignition scripting functions](https://docs.inductiveautomation.com/display/DOC80/Scripting+Functions), but you’ll find documentation on the window actions by [searching the internet for “JFrame”](https://www.startpage.com/do/search?cat=web&language=english&query=JFrame), the Java component that contains an Ignition desktop.

---

<div class="post-metadata">

**Author:** ![andrew.thull](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@andrew.thull](https://forum.inductiveautomation.com/u/andrew.thull)\
**Post date:** [February 25, 2021, 3:29pm UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/6 "2021-02-25T15:29:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 25, 2021, 4:14pm UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/7 "2021-02-25T16:14:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![andrew.thull](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@andrew.thull](https://forum.inductiveautomation.com/u/andrew.thull)\
**Post date:** [February 25, 2021, 4:39pm UTC](https://forum.inductiveautomation.com/t/max-window-size-in-different-monitors/32030/8 "2021-02-25T16:39:39Z")

</div>

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.
