tags:

views:

93

answers:

4

I'm developing a Swing-based Java application in Eclipse on Windows XP. I have a dual monitor setup.

I want to have the program launch on a different monitor than the one I'm running Eclipse in. How can I set up my Debug Configuration to make this happen?

A: 

I think you can't do that. The only solution I found is to move the program from the first display to the second one manually and then close it in this position (with the close button and not the Console terminate red button that stop brutally the VM without saving anything). Then on the next restart, your program launch should appear on the second display. In order to have this solution working, your launch configuration should not clear the workspace and the config at each launch in order to keep the programm screen location.

See http://stackoverflow.com/questions/3184999/rcp-opening-monitor for related stuff on RCP app.

Manuel Selva
That would work for an RCP app, but not for a Swing app.
zvikico
Oopppsss zvikico is right, my answer is Ok for an RCP app but not a Swing one. I didn't get the question correctly, sorry.
Manuel Selva
A: 

You can probably achieve that behavior programmatically. I'm sure you can Google and find examples of how to open your window on the second monitor. If it is something you want only at debug-time, add a switch in your launch configuration (more specifically, a JVM runtime argument) and check for the switch (System.getProperty) when your program starts.

zvikico
I don't want to have to modify my code to do this, it's probably possible to control the programs' default window within the java code, but this is not an option. I'd like to set up Eclipse to do this, so that I can reuse the setting across multiple projects. If there are JVM runtime arguments to select the default monitor, that's exactly what I'm after. You don't happen to know what they are, do you?
Tom Tresansky
I'm not familiar with such option. It depends on the implementation of the GraphicsEnvironment/GraphicsConfiguration. You could write a reusable component and use it throughout your projects. It will not affect your production code.
zvikico
+1  A: 

It depends a bit how you did set up your second monitor. For my answer, I'm assuming that you added it as an "extension" to your desktop (so you can move windows between them by dragging with the mouse).

In this mode, your desktop becomes bigger. To see that, call GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds.

The width should be the sum of the widths of your two monitors and the height should be the larger of the two heights.

Note that the x coordinate can be < 0 (this happens if your make the right monitor the default one).

To move your window to the other monitor, simply use a position (setPosition()) with an appropriate value and pass that position as an option to the program. Or save the current position as a preferences node and open the window again in the same place when the app is run again.

If your monitors are configured independently, you should look into the GraphicsEnvironment.getScreenDevices() API.

Aaron Digulla
+1  A: 

When a new frame is opened, it defaults to coordinates 0,0. Exactly where this is depends on your operating system's monitor layout. Typically, 0,0 will be the upper-left corner of the primary monitor.

The solution to your problem is to run Eclipse on your secondary monitor, so that the applications will open on the other (primary) monitor. You don't actually have to move Eclipse to do this. Go into your operating system's monitor settings and switch the primary monitor to the monitor you wish to start the application on. Eclipse will now be running on the secondary monitor.

Your new frame will now be opened on the other monitor, and you have changed no code in the process, just your operating system's configuration settings.

Erick Robertson
Thanks, this seems to do the trick!
Tom Tresansky