Search code examples
javaswingwindowscreen

Find which screen window is on


How can I detect which screen a JFrame is located on? I need to find the screen and resize the frame to make sure it is not larger than the relevant screen.


Solution

  • For the purpose you mention, you can call frame.getGraphicsConfiguration().getBounds(). If you actually want to query other things about the display device itself, use frame.getGraphicsConfiguration().getDevice() (as well as other methods in the GraphicsConfiguration), which might get you some interesting things.