Placing setLocation() in setup() won`t work b/c the canvas is invisible then.
And only after setup() has finished, Processing takes care of its latest adjustments.
And that includes setLocation(), overriding ours! :O
In order to avoid redundant repeating calls to setLocation() within draw(),
we can make a thread("") function for the sole purpose to wait & reposition the canvas after it isVisible()!
/**
* Reposition Canvas (v1.01)
* by GoToLoop (2014/Apr)
*
* forum.processing.org/two/discussion/4712/window-location
*/
static final int WINDOW_X = 300, WINDOW_Y = 400;
static final int FPS = 60, FREQ = (1<<5) - 1;
void setup() {
size(800, 600, JAVA2D);
frameRate(FPS);
smooth(4);
thread("repositionCanvas");
}
void draw() {
//if (frameCount % FREQ == 0)
if ((frameCount & FREQ) == 0)
background((color) random(#000000));
}
void repositionCanvas() {
while (!frame.isVisible()) delay(2);
frame.setLocation(WINDOW_X, WINDOW_Y);
}
That code and also frame.setLocation(int, int) work in processing. But I try to build my program in eclipse. This code does not work too in eclipse (like also frame.setLocation(int, int) in draw()).
I forgot about the need to be in draw() to call this method. But you can call it only once by using a boolean or doing this only at frameCount == 2, for example.
Answers
It works for me! :)]
Why do you put this in draw(), anyway? No need to repeat this over and over.
So say me where I must put it in? Do you think that in setup()?
Placing setLocation() in setup() won`t work b/c the canvas is invisible then.
And only after setup() has finished, Processing takes care of its latest adjustments.
And that includes setLocation(), overriding ours! :O
In order to avoid redundant repeating calls to setLocation() within draw(),
we can make a thread("") function for the sole purpose to wait & reposition the canvas after it isVisible()!
That code and also frame.setLocation(int, int) work in processing. But I try to build my program in eclipse. This code does not work too in eclipse (like also frame.setLocation(int, int) in draw()).
Just maybe you need to
import java.awt.Window;
or something like that?Processing auto-imports a bunch of Java's standard libraries!
http://docs.oracle.com/javase/8/docs/api/java/awt/Window.html#setLocation-int-int-
That does not work in eclipse. It means by processing code, it does not seem possible to move it. So I have to focus on classical ways...
I only know Processing's IDE for now, sorry!
But I wonder where's the main() function in your code? Or perhaps Eclipse takes care of that too? X_X
In case it doesn't, here's another more advanced attempt of mine:
I forgot about the need to be in draw() to call this method. But you can call it only once by using a boolean or doing this only at frameCount == 2, for example.