Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the screen resolution in java? [duplicate]

Tags:

java

Possible Duplicate:
Screen resolution java

Hi,

How can I get screen resolution in Java?

like image 990
Mahdi_Nine Avatar asked Apr 16 '11 21:04

Mahdi_Nine


2 Answers

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();
like image 105
mdma Avatar answered Sep 30 '22 23:09

mdma


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

like image 21
Bastardo Avatar answered Sep 30 '22 23:09

Bastardo