java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to get screen's display mode information?

This example shows graphics devices display mode information such as the display width, height, refresh rate and bit depth. This information can be obtained from GraphicsDevice.getDisplayMode() method which return an instance of java.awt.DisplayMode.

We can also get the size of a screen using the following example [How to get my screen size?], but this example can handle only a single screen.

package com.javacoderanch.example.awt;

import java.awt.*;

public class GettingScreenDisplayModeInformation {
    public static void main(String[] args) {
        //
        // Get local graphics environment
        //
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

        GraphicsDevice[] devices = env.getScreenDevices();

        int sequence = 1;
        for (GraphicsDevice device : devices) {
            System.out.println("Screen Number [" + (sequence++) + "]");
            System.out.println("Width       : " + device.getDisplayMode().getWidth());
            System.out.println("Height      : " + device.getDisplayMode().getHeight());
            System.out.println("Refresh Rate: " + device.getDisplayMode().getRefreshRate());
            System.out.println("Bit Depth   : " + device.getDisplayMode().getBitDepth());
            System.out.println("");
        }
    }
}

An example of the program result:

Screen Number [1]
Width       : 1280
Height      : 1024
Refresh Rate: 60
Bit Depth   : 32

Screen Number [2]
Width       : 1280
Height      : 800
Refresh Rate: 60
Bit Depth   : 32