File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem in detecting Resolution change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in detecting Resolution change" Watch "Problem in detecting Resolution change" New topic
Author

Problem in detecting Resolution change

Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Hi folks,

I need a help regarding detection of Resolution Change in system using java.I already have a piece of working code to bring up my frame which contains lot of components included in it. Now i need to include one more module which detects for resolution change under my windows machine.

I got one idea but i don't know whether that one is well suited for this scenario.
I just thought of writing a separate timer thread which detect system resolution(every second) and react accordingly.

Is there any other way we can detect System Resolution change under Java???

Are there any event handlers in java for handling this scenario???
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
I think you might have to write a JNI interface into windows land, and have a native module listern for resolution chnage messages.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by Gavin Tranter:
I think you might have to write a JNI interface into windows land, and have a native module listern for resolution chnage messages.


Thanks Gavin Tranter,for your input.Instead of writing a separate JNI interface i thought of making it work like this

I have written a separate timer thread that detects System Resolution and performs some task. I can start that timer thread once my application lost focus and stop the thread once my application gain focus.

Is this solution will result in any problem in future???
else i really need to switch over to JNI interface
[ June 17, 2008: Message edited by: Balasubramanian Chandrasekaran ]
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
How do you plan to test the resolution?

Unless there are classes in the java 2D package that can detect the current resolution, i dont see how this can be done without JNI.

I think either way you will end up with a thread that periodically detects the resolution change. I would set it up to be a very lightweight thread that fires an event that the main app can listern for.

Is a reason that you need to check for a resolution change? I would have thought that resolutions are generally static on a given machine, I know the only time I change mine is when a game automatically changes it or a get a better graphics card/monitor.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215


How do you plan to test the resolution?

Unless there are classes in the java 2D package that can detect the current resolution, i dont see how this can be done without JNI.



I am able to get current screen resolution using the call




Is a reason that you need to check for a resolution change?

Thats because of client requirements.They want the application to be displayed differently under different resolutions.
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Ah. Cool, didnt know/remember that.
Yeah I would use a lightweigth thread that when it detected a change fires off an event, that the main app catches.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by Gavin Tranter:
Ah. Cool, didnt know/remember that.
Yeah I would use a lightweigth thread that when it detected a change fires off an event, that the main app catches.


Thanks for your comments. I will move ahead with that lightweight thread approach.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Balasubramanian Chandrasekaran:

I am able to get current screen resolution using the call


code:
--------------------------------------------------------------------------------

Toolkit.getDefaultToolkit().getScreenSize();

--------------------------------------------------------------------------------



This won't work correctly on systems with multiple screens when your application is being displayed on a different than the primary screen. You'd better ask your components for their toolkits.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in detecting Resolution change