Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect screen resolution change made by user (Java Listener?)

I have a Java app that launches, creates a GUI and works great. If the user changes the screen resolution (switches from 1440x900 to 1280x768), I'd like to be able to listen for that event.

Any ideas?

PS - I'd like to do this in event/listener mode, not in poll mode, so that extra CPU cycles aren't wasted on something like a timer constantly polling the screen size every N seconds to see if it's changed.

like image 786
Rick Hodgin Avatar asked Sep 17 '11 13:09

Rick Hodgin


2 Answers

This post is old, but: - polling the screen size once every second will not have any impact on performance - when the screen is resized, every window should receive a repaint() call (you need to test this for the OSs you target)

like image 69
JayC Avatar answered Sep 18 '22 19:09

JayC


I don't think that Java can do this by itself. You would have to have a "hook" into the operating system that detects this change and may wish to consider using JNA, JNI, or a separate utility such as perhaps Sigar that reports to your Java program. Out of curiosity, why do you wish to do this? Is it for a game you're making or so that you can re-size a GUI application?

like image 22
Hovercraft Full Of Eels Avatar answered Sep 18 '22 19:09

Hovercraft Full Of Eels