aspose file tools*
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Similar Threads
Middling The JFrame
Is it worth using this initialization block?
ideas wanted on making this custom JTable cell renderer more efficient
Graphics Graphics Graphics - Where are my circles?
problem in minimizing & maximizing frame.