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

后端 未结 5 1128
失恋的感觉
失恋的感觉 2021-01-17 19:17

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 list

5条回答
  •  醉梦人生
    2021-01-17 19:58

    You can create a global PAINT listener to detect screen resize.

    // 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);
    

提交回复
热议问题