Java: Getting resolutions of one/all available monitors (instead of the whole desktop)?

前端 未结 1 1339
我在风中等你
我在风中等你 2020-12-20 11:37

I have two different-sized monitors, connected together using (I believe) TwinView.

I tried

System.out.println(Toolkit.getDefaultToolkit().getScreenS         


        
相关标签:
1条回答
  • 2020-12-20 12:20

    you'll want to use the GraphicsEnvironment.

    In particular, getScreenDevices() returns an array of GraphicsDevice objects from which you can read the width/height of the display mode.

    Example:

    GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = g.getScreenDevices();
    
    for (int i = 0; i < devices.length; i++) {
        System.out.println("Width:" + devices[i].getDisplayMode().getWidth());
        System.out.println("Height:" + devices[i].getDisplayMode().getHeight());
    } 
    
    0 讨论(0)
提交回复
热议问题