|
How to retrieve the size of the Screen in Java |
|
|
This Java tip illustrates a method of getting the size of the screen. The developer may use
getScreenSize() to get the size of the default screen.
// Current size of the default screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
Further, in case one or more screens are present, the developer may get the size of the
screen by using a for loop as illustrated below.
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = environment.getScreenDevices();
// Get size of each screen
for (int i=0; i<devices.length; i++) {
DisplayMode dmode = devices[i].getDisplayMode();
int screenWidth = dmode.getWidth();
int screenHeight = dmode.getHeight();
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.