I've just started creating an application in Processing, and I'm getting unpredictable behaviour when I place a PApplet object into a JFrame using BorderLayout.CENTER.
The width of the PApplet is 100 less than the width and height of the JFrame. On some occasions, when I click 'Run', the program fills the screen and runs really smoothly, but on other runs, the PApplet starts from the top left and leaves a gap on 100 on the bottom of the screen and left hand side, and is quite laggy.
I have no idea what is going on if I'm honest.
This is the result which runs smoothly:
This is the unpredictable one:
Here is the code I'm using:
PApplet subclass
public class JCanvas extends PApplet {
/**
* PApplet method - performs all setup actions
*/
public void setup(){
size(1400,900,P3D);
background(80);
}
/**
* PApplet method - All drawing occurs here
*/
public void draw(){
background(80);
pushMatrix();
translate(mouseX,mouseY, -199);
fill(220,0,0);
box(120,500,90);
popMatrix();
}
}
Viewer class
public final class EuroViewer {
private final static int WIDTH = 1500;
private final static int HEIGHT = 1000;
private final static boolean RESIZABLE = false;
public static void main(String[] arguments){
final JFrame frame = new JFrame("Eurographics PApplet");
JCanvas sketchCanvas = new JCanvas();
frame.add( sketchCanvas );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(RESIZABLE);
frame.setLocationRelativeTo(null);
sketchCanvas.init();
frame.setVisible(true);
}
}
I then tried to replace JFrame with awt.Frame incase there was some stability issues between Swing and awt (which I'm led to believe PApplet is built off of) in this paticular case.
Surprisingly enough though, there is never any lag with Frame, which has kind of solved the issue. But, I've always used JFrame, any GUI work with containers etc I've always done with Swing, so I was wondering if anyone could share their knowledge and explain what is going on, and if it would be possible to fix? this issue.
Thanks.