1

I wish to determine the screen resolution where my java application is currently showing.

For example, lets say a user has my java application on his second monitor and the two monitors have the specifications of: primary 1024x1280 (Portrait rotation), secondary 1280x1024 (Landscape rotation).

I want to make the height of my popup JList fit within a comfortable margin of the second monitor. I won't get the correct results from Toolkit#getDefaultToolkit()#getScreenSize() as this would give me the dimensions from the primary monitor.

I could get the size of all the monitors by using GraphicsEnvironment#getScreenDevices() but how do I figure out which of these devices my JFrame is running within?

Thanks for your time.

-Dennis

D-Klotz
  • 1,973
  • 1
  • 15
  • 37
  • Take the Rectangle bounds of the frame and determine if it fits inside the Rectangle bounds of any of the GraphicsDevices. For [example](http://stackoverflow.com/questions/11714215/detect-current-screen-bounds/11714302#11714302) – MadProgrammer Aug 09 '13 at 20:07

2 Answers2

3

Assuming frame is your JFrame, you can simply use the following code to retrieve the GraphicsDevice:

frame.getGraphicsConfiguration().getDevice();

From there, you can get the whole the information of the screen on which the frame is displayed.

Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117
2

check out this link . the answer is already explained here. ( The accepted answer ) Java Toolkit Getting Second screen size

you can get from a JFrame to its device via the getGraphicsConfigration() method, which returns a GraphicsConfiguration that has a getDevice()

Community
  • 1
  • 1
Kinaan Khan Sherwani
  • 1,504
  • 16
  • 28