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 do I get my screen size?, but this example can handle only a single screen.
package org.kodejava.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 : 2560
Height : 1080
Refresh Rate: 60
Bit Depth : 32
Screen Number [2]
Width : 2560
Height : 1080
Refresh Rate: 60
Bit Depth : 32