Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I tried

System.out.println(Toolkit.getDefaultToolkit().getScreenSize());

and get

java.awt.Dimension[width=2960,height=1050]

which is true if you count both monitors together.

Instead of this, I would like to be able achieving one of the following:

  • getting resolution of the current monitor
  • getting resolution of the main monitor
like image 393
ivan_ivanovich_ivanoff Avatar asked May 18 '09 12:05

ivan_ivanovich_ivanoff


People also ask

How do I change my screen resolution in Java?

To change display mode with Java Swings, use the setDisplayMode() method. Here, we have set the Display mode as: new DisplayMode(800, 600, 32, 60)); Now, when you will run the program, the frame would be visible in a different resolution than the actual set resolution of your system.

What does FHD mean in monitors?

Full HD means that a monitor has 1920 pixels horizontally across the screen and 1080 pixels vertically, or 1920x1080, and that's why it's sometimes also shortened to 1080p. If you want to enjoy Full HD content, it's not enough to just have a Full HD TV or projector.

How do I Auto Detect my screen resolution?

Very simple. Go to 'settings,' then click 'system,' then click 'display,' then 'advanced display settings. ' The recommended resolution is your native resolution, and the one that you should be using.

How much resolution is FHD?

These days when we say HD we're talking about what gets called 'Full HD', a resolution which measures 1,920 x 1,080 pixels, often called 1080p. This display resolution is common on Smart TVs and many modern smartphones, PCs, laptops and monitors.


1 Answers

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());
} 
like image 104
z - Avatar answered Nov 16 '22 00:11

z -