Get Screen Size of Each Monitor using Java

java.awt package

package app;

import java.awt.*;

public class Main
{
    public static void main(String[] args)
    {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        for (GraphicsDevice gd : ge.getScreenDevices()) {
            Rectangle rectangle = gd.getDefaultConfiguration().getBounds();
            int width = (int) rectangle.getWidth();
            int height = (int) rectangle.getHeight();

            System.out.println(width + "x" + height);
        }
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.