5

Possible Duplicate:
Screen resolution java

Hi,

How can I get screen resolution in Java?

Community
  • 1
  • 1
Mahdi_Nine
  • 13,285
  • 26
  • 79
  • 116

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
  • 55,741
  • 11
  • 90
  • 126
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,106
  • 9
  • 40
  • 59
2

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

lobster1234
  • 7,609
  • 25
  • 29