How can I get screen resolution in java?

AndreDurao :

How can one get the screen resolution (width x height) in pixels?

I am using a JFrame and the java swing methods.

Colin Hebert :

You can get the screen size with the Toolkit.getScreenSize() method.

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();

On a multi-monitor configuration you should use this :

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();

If you want to get the screen resolution in DPI you'll have to use the getScreenResolution() method on Toolkit.


Resources :

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get the screen resolution using SDL2?

Java Tookit Screen Resolution - How can I use it?

How can I increase my screen resolution?

How can I increase screen resolution?

How can I get an app bar to stay at the bottom regardless of screen resolution?

How can I get the current screen resolution from the command line on OS X?

Why can't I get the right screen resolution in Ubuntu?

How can I change plane size with different screen resolution?

How can I set the resolution and rotate the screen of an app launched with startx

How can I change the resolution of my screen in pygame

How can I prevent an application (or user) from changing the screen resolution?

How can I adjust the resolution to avoid the damaged area on my screen?

how can i increase the screen resolution ubuntu 15.10?

How can I make this notebook scale to the screen resolution in tkinter?

How do I get screen resolution in a shell script on Linux

how to get the screen resolution in python?

Remote desktop: Fullscreen is limited to the resolution of my primary monitor. How can I get a full screen rdp session on my second (bigger) screen?

How can I get the current screen orientation?

How I can get screen orientation?

How can I get millisecond and microsecond-resolution timestamps in Python?

How can I get the monitor resolution using the command line?

How can I get the resolution inputted in a XxY format?

How to get display resolution (screen size)?

How to get screen resolution in pixels in Octave?

How to get screen resolution and save it to a text file?

How can I get a component's position on screen (screen coordinates)

How can i resize the video bytes to smaller resolution in java?

How can I fix resolution/screen size issues when connected to a server via RDP?

How can I fix my vista PCs screen resolution and refresh rate