Night | Snow

Getting the Screen Size in Java

Posted on: January 6th, 2010

Tags: ,

Here’s a little exmple on how to get the screen size of one or multiple monitors in Java.

Get the size of the default screen:

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

If more than one screen is available, this example gets the size of each screen:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();

// Get size of each screen
for (int i=0; i<gs.length; i++) {
    DisplayMode dm = gs[i].getDisplayMode();
    int screenWidth = dm.getWidth();
    int screenHeight = dm.getHeight();
}

News

Martin Fischer said:

Client and partner of simra.ch

Wir können Simon Schärer als kompetenter und zuverlässiger Programmierer höchst weiterempfehlen. Er ist nicht nur ein guter Programmierer, sondern auch ein ausgezeichneter Designer.
Danke Developer’s Island

Follow us on Twitter

favorite

I get asked a lot - which SDK should we use for web programming? I recommend Netbeans

my toolbar

Simra GameMP3 playersubscribe to RSSMy delicious bookmarksFacebookTwitterE-mail

No Responses to “Getting the Screen Size in Java”

RSS Feed Icon  Subscribe to comments follow-up

Trackbacks/Pingbacks

Leave a reply

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Latest Tweet

loading...