File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes being notified of screen resolution changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "being notified of screen resolution changes" Watch "being notified of screen resolution changes" New topic

being notified of screen resolution changes

Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311

We have a swing application, where component sizes are set relative to screen size (this is a *strict* requirement from the customer).
Example: some frame should occupy exactly 1/2 the screen width & height. So (eliminating insets for simplicity):

The problem is, it doesn't work when user changes screen resolution at runtime.
For instance:
1. Invoke the program with a 800x600 resolution: frame will pop up with 400x300 size
2. While frame is showing, change screen resolution (through the operating system) to 1280x960
3. Now, of course, frame is still 400x300 , which is no longer half the screen. Customer would like to to be fixed (1280/2 , 960/2).

Could anyone offer a solution to this ?
In particular, is there any sort of event we can catch to be notified of screen resolution changes ?
(I have considered overriding the frame's paint(Graphics) method, because I've noticed that, at least on winXP, frames are minimized & then maximized when resolution changes; which triggers a call to paint(). So one could override paint() so that it re-checks frame size... but this does not seem very elegant ).

Thanks in advance
I agree. Here's the link:
subject: being notified of screen resolution changes
It's not a secret anymore!