English 中文(简体)
• 检测用户改变解决办法(Java Listener?)
原标题: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——我想以事件/名单方式,而不是以投票方式这样做,这样,在像一个时间者一样不断投票时,会把CPU以外的周期推到每个N秒的屏幕大小上,看它是否发生了变化。

问题回答

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)

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?

除了手工艺品建议外,你还可以考虑一种背景线,即利用<条码>对现行屏幕分辨率进行监测。

你们需要对此进行测试,以发现这一read对系统的影响如何大。 如何经常检查变化取决于您的要求(如何迅速满足您对变化的反应要求)

你们可以创建全球太平洋电信联盟的听众,以检测转播情况。

// screen resize listener
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
// take a look at http://stackoverflow.com/questions/10123735/get-effective-screen-size-from-java
            Rectangle newSize = getEffectiveScreenSize(); 
            if (newSize.width != windowSize.width || newSize.height != windowSize.height)
                resize();

        }
    }, AWTEvent.PAINT_EVENT_MASK);

我在此建议解决这一问题。

  1. Every swing object can implement an interface called java.awt.event.ComponentListener.
  2. One of its method is componentResized(ComponentEvent e).
  3. Your main application frame should implement this interface and override the resize event method. This is how you listen to the resize event, Checkout this link . I hope this helps you.




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签