We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm back, with another conundrum!
I always have an external monitor attached, and I consistently run sketches on both my main and external monitor, often time in present mode. Is there a way to, in code, tell which monitor to run the sketch on, rather than having to tediously change it in the settings each time?
I know you can do frame.setLocation(x,y), but is that the only way to define where the window ends up? What does the setting in preferences actually do behind the scenes, and can I access that in code?
Answers
http://forum.Processing.org/two/discussions/tagged?Tag="--display"
To find out what's going on behind the scenes, the best thing to do is to go to the code: https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java
It looks like that settings eventually feeds into variables called
display
anddisplayNum
, which then gets used byinitFrame()
on line 10320 of PApplet:surface.initFrame(this); //, backgroundColor, displayNum, fullScreen, spanDisplays);
If you're in AWT mode,
PSurfaceAWT
then uses the displayNum to get a GraphicsConfiguration:I've taken out comments to make it more concise, but that last line is the meat and potatoes of your question. That
JFrame
constructor takes aGraphicsConfiguration
, which tells it which monitor to display on.I would expect us to be able to use similar logic:
(source)
However, that
showOnScreen()
function doesn't seem to have any effect, althoughgd[screen].getDefaultConfiguration().getBounds().x
does return the correct result. Maybe that'll get you closer to your goal, at least.