# Determining window size

**URL:** <https://forum.inductiveautomation.com/t/determining-window-size/2525>\
**Category:** Ignition\
**Created:** [January 18, 2011, 6:53pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525 "2011-01-18T18:53:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MCC](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MCC](https://forum.inductiveautomation.com/u/MCC)\
**Post date:** [January 18, 2011, 6:53pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/1 "2011-01-18T18:53:50Z")

</div>

This thread relates to the one on supporting clients with varying resolutions. We have experimented with various relative and fixed layouts with anchors. These settings are OK for some screen resizing, but some issues like widescreen vs 4:3, can’t really be gotten around. You pretty much end up leaving a bunch of empty real estate on one side if you want a 4:3 aspect ratio client to be able to view the screen acceptably.

I was wondering if there was any way to know in scripting what the size of the Vision window is and what the size of the client desktop is. That way we might be able to have differing default layouts and screens for various clients. I don’t see anything in the system area of the scripting manual.

Thanks for your assistance.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [January 18, 2011, 7:09pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/2 "2011-01-18T19:09:42Z")

</div>

Yes, you’re right - making content that look equally good on standard aspect ratio and wide-screen aspect ratio is downright hard (not just in our software either - this is pretty much true for anything).

Getting the size of an open window from an event handler is easy:

`window = system.gui.getParentWindow(event)
print "Window size is: %dx%d" % (window.width, window.height)`

Getting the size of the client also possible from an event handler:

[code]from javax.swing import JFrame, SwingUtilities

window = system.gui.getParentWindow(event)

frame = SwingUtilities.getAncestorOfClass(JFrame, window)  
print “Frame size is: %dx%d” % (frame.width, frame.height)[/code]

Hope this helps,

---

<div class="post-metadata">

**Author:** ![MCC](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MCC](https://forum.inductiveautomation.com/u/MCC)\
**Post date:** [January 18, 2011, 8:25pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/3 "2011-01-18T20:25:51Z")

</div>

Thanks, Carl. That is a big help.

---

<div class="post-metadata">

**Author:** ![MCC](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MCC](https://forum.inductiveautomation.com/u/MCC)\
**Post date:** [January 18, 2011, 9:42pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/4 "2011-01-18T21:42:44Z")

</div>

I tried that out and it works well to get the size of a window and the size of the frame that Ignition is filling. This one might be trickier since it needs to get information from the client OS… Is there a way to get the size of the operating system desktop?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [January 18, 2011, 9:50pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/5 "2011-01-18T21:50:54Z")

</div>

Sure, thats no problem.

[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]

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [January 18, 2011, 10:09pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/6 "2011-01-18T22:09:12Z")

</div>

[quote=“MCC”]…but some issues like widescreen vs 4:3, can’t really be gotten around. You pretty much end up leaving a bunch of empty real estate on one side if you want a 4:3 aspect ratio client to be able to view the screen acceptably…[quote]

Fwiw, I had the same issue at a customer site. They had everything from nice wide screens to small 4:3 monitors. I didn’t want separate screens or projects, so I ended up using the setFont, resizeComponent, and moveComponent functions to dynamically populate the screen upon opening. I did it by detecting the size of the containers, but windows would work the same way.

It came out very nice, and the screens look great even on the cheesyist monitors.

---

<div class="post-metadata">

**Author:** ![liuwf2139](https://avatars.discourse-cdn.com/v4/letter/l/48db29/32.png) [@liuwf2139](https://forum.inductiveautomation.com/u/liuwf2139)\
**Post date:** [July 5, 2019, 8:47am UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/7 "2019-07-05T08:47:01Z")

</div>

Hi,  
Step7, could you share your code. I’d like to use it on Perspective Module, is it possible?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 5, 2019, 2:12pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/8 "2019-07-05T14:12:58Z")

</div>

Step7’s code would be for Vision Windows which means it will not work for Perspective. Many users have requested this feature for Perspective, but few have actually upvoted the [requested feature](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/expose-viewport-dimensions-in-perspective).

---

<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:30am UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/9 "2020-02-07T04:30:51Z")

</div>

> [@Carl.Gould](#):
>
> 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)

Dear Carl. Please Help!! I don't know where I should run this code.  
On a component? on a window? on a script console?

when I run it on script console I get:

```auto
SyntaxError: (u"no viable alternative at character '\u201c'", ('<input>', 5, 6, u'print \u201cThe main screen is %dx%d\u201d % (size.width, size.height)\n'))

```

---

<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:07am UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/10 "2020-02-07T06:07:07Z")

</div>

> [@jespinmartin1](#):
>
> print “The main screen is %dx%d” % (size.width, size.height)

That error is due to the curly quotes `“”` around the print statement (many text editors auto-replace straight quotes with these, and forum upgrade since original post may have done so). Replace them with straight quotes `""` and it will run in the script console.

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

```

```plaintext
>>> 
The main screen is 1366x768
>>> 

```

---

<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:03pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/11 "2020-02-07T13:03:30Z")

</div>

oh wow. Thanks for your help. It worked

---

<div class="post-metadata">

**Author:** ![weertske](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weertske/32/3353_2.png) [@weertske](https://forum.inductiveautomation.com/u/weertske)\
**Post date:** [February 16, 2020, 6:08pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/12 "2020-02-16T18:08:54Z")

</div>

It would be nice if I could login to vote. Perhaps there is something broken with the Ignition Features and Ideas site.

There is a way to determine screen width (viewport) in Perspective. We are using the result regularly to modify tag history query density, adjust font, etc. I have held back on posting how to do it so Inductive could post a more controlled solution. What are your plans?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 16, 2020, 6:55pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/13 "2020-02-16T18:55:35Z")

</div>

> [@weertske](#):
>
> Perhaps there is something broken with the Ignition Features and Ideas site.

There is. It delegates to [canny.io](http://canny.io) via a third-party cookie. Tight browser security breaks this. A secure method of passing the session status is in the works, but I haven't received a time estimate.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 18, 2020, 3:22pm UTC](https://forum.inductiveautomation.com/t/determining-window-size/2525/14 "2020-02-18T15:22:43Z")

</div>

We’ve had an internal ticket to provide viewport properties as a new feature for over a year now. There does seem to have been some bookkeeping done on the ticket recently so it’s not something I would consider to be “lost in the ether”, but it’s also not a priority.

The feature would include viewport dimensions, screen dimensions, and scroll values as session properties.
