5

Possible Duplicate:
Screen resolution java

Hi,

How can I get screen resolution in Java?

Community
  • 1
  • 1
Mahdi_Nine
  • 14,205
  • 26
  • 82
  • 117

3 Answers3

19

You can use AWT Toolkit,

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

or better java2d, which supports multi monitor setups:

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
mdma
  • 56,943
  • 12
  • 94
  • 128
4

You can determine the screen resolution (screen size) using the Toolkit class. This method call returns the screen resolution in pixels, and stores the results in a Dimension object, as shown here:

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

You can then get the screen width and height as int's by directly accessing the width and height fields of the Dimension class, like this:

screenHeight = screenSize.height;
screenWidth = screenSize.width;

check this

another method

Bastardo
  • 4,144
  • 9
  • 41
  • 60
2

By using java.awt.Toolkit's getScreenSize() method.

lobster1234
  • 7,679
  • 26
  • 30