Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

Java Toolkit Getting Second screen size

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:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...