Java Toolkit Getting Second screen size

前端 未结 4 1626
粉色の甜心
粉色の甜心 2020-11-29 10:24

I have two screens plugged into my computer and was wondering if there was a way in JFrame or Toolkit of detecting which screen the window is on?

I have this code:

4条回答
  •  眼角桃花
    2020-11-29 11:07

    You should take a look at GraphicsEnvironment.

    In particular, getScreenDevices():

    Returns an array of all of the screen GraphicsDevice objects.

    You can get the dimensions from those GraphicDevice objects (indirectly, via getDisplayMode). (That page also shows how to put a frame on a specific device.)

    And you can get from a JFrame to its device via the getGraphicsConfigration() method, which returns a GraphicsConfiguration that has a getDevice(). (The getIDstring() method will probably enable you to differentiate between the screens.)

提交回复
热议问题