Java Toolkit获得第二个屏幕大小 [英] Java Toolkit Getting Second screen size

查看:228
本文介绍了Java Toolkit获得第二个屏幕大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个屏幕插入我的电脑,想知道JFrame或Toolkit是否有办法检测窗口在哪个屏幕上?

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?

我有这个代码:

java.awt.Toolkit.getDefaultToolkit().getScreenSize();

哪个获取我的主屏幕的屏幕大小,但我怎样才能获得第二个屏幕的大小,或者检测窗口在哪个屏幕上?

Which gets my screen size of my main screen, but how can I get the size of my second screen, or detect which screen the window is on?

推荐答案

你应该看一下 GraphicsEnvironment

特别是, getScreenDevices()


返回所有数组的数组屏幕GraphicsDevice对象。

Returns an array of all of the screen GraphicsDevice objects.

您可以从 GraphicDevice 对象(间接地,通过 getDisplayMode )。 (该页面还显示了如何在特定设备上放置框架。)

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.)

您可以通过 getGraphicsConfigration() 方法,返回 GraphicsConfiguration 具有 getDevice()。 ( getIDstring()方法可能会让您区分屏幕。)

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.)

这篇关于Java Toolkit获得第二个屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆