Solved

How to known if OS is running more than 1 monitor.

Posted on 2001-06-08
5
228 Views
Last Modified: 2012-06-21
I have two monitors. I am running an application in the second monitor and saves cordinates in a file. When I move the application to another computer that only have 1 monitor the window is not visible due to location outside the monitor.


Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

gets me 1600x1200
But my windows is located lets say 1680x150 and not visible.
I could remove 1600 from the 1680 automatically. But I want to support more monitors.

There is a method
Toolkit.getDefaultToolkit().getDesktopProperty(StringPopertyName);

Does anyone know what property I should look for?
Or some way to ask the OS number of monitors etc.
0
Comment
Question by:lawpan
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6167941
Please have a look at:

http://java.sun.com/j2se/1.3/docs/guide/awt/enhancements.html

They tell you how to support more than one monitor.

I will look for a solution working in Swing. Stay tuned.
0
 
LVL 3

Accepted Solution

by:
dnoelpp earned 150 total points
ID: 6167993
Try the following code:

GraphicsDevice[] devices = GraphiceEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

System.out.println("device count: " + devices.length);

// Select default configuration of screen 0:

GraphicsConfiguration gc0 = devices[0].getDefaultConfiguration();

// create a JFrame on screen 0
JFrame f = new JFrame(gc0);

// Select default configuration of screen 1, if existent, or throw IndexOutOfBoundsException

GraphicsConfiguration gc1 = devices[1].getDefaultConfiguration();

// create a JFrame on screen 1
JFrame f = new JFrame(gc1);


* * * * * * *

The idea is: A GraphicsDevice describes a device you can paint on. This is a screen, a printer, etc.

Each device now has several configurations. Maybe for screens it is meant: color or black and white. But I think just take the default configuration and you should be fine. Then pass that configuration to the Frame or a JFrame-constructor. And that's it!
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6168072
Oops, a typo! Should be GraphicsEnvironment instead of GraphiceEnvironment.

Sorry!
0
 

Author Comment

by:lawpan
ID: 6176003
Thank you very much. This was what I was looking for.
0
 

Author Comment

by:lawpan
ID: 6180041
Thank you very much. This was what I was looking for.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now