javamultiple-monitorssystem-properties

How to know if a computer has multiple monitors connected to it?


My system monitoring app takes screenshot every five minutes it runs in a system. But for a system connected in dual monitor mode needs a different set of codes to take the complete 180 degree screenshot.

Is there a way to know if the system is working in dual monitor mode by some means(system property)?


Solution

  • you can use GraphicsEnvironment https://docs.oracle.com/javase/7/docs/api/java/awt/GraphicsEnvironment.html :

    private String getMonitorSizes() {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[]    gs = ge.getScreenDevices();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < gs.length; i++) {
            DisplayMode dm = gs[i].getDisplayMode();
            sb.append(i + ", width: " + dm.getWidth() + ", height: " + dm.getHeight() + "\n");
        }
        return sb.toString();
    }