How to trigger a painting of the draw area when a PApplet is just added (embedded) into a JFrame ?
in
Integration and Hardware
•
2 years ago
Hi,
I am trying to draw a picture in the "setup" method of a PApplet and then add (or embed) the PApplet into a JFrame. I have used "noLoop" in the last line of "setup" and have not used the "draw" method (I leave it blank). I have used the same size for the PApplet and the JFrame. However, when the JFrame is displayed, only a blank picture is shown on the PApplet's drawing area. The drawing area keeps blank until I perform an initial mouse click on this area. The drawing area then shows the blue rectangle correctly (but just after an initial mouse click).
The code snippet of the PApplet's program (in Java) is shown below :
public void setup() {
size(500, 500, P2D);
drawImpl();
// do something else not related to drawing
noLoop();
}
public void drawImpl() {
stroke(50);
fill(0,0,255);
translate(0, 0);
rect(0,0,30,30);
}
It seems that the blue rectangle is drawn normally in the PApplet's drawing area but Java has just not painted the PApplet's drawing area initially.
Is there any way that I can put some Java codes into the PApplet's program or the JFrame's program to trigger the initial painting of the drawing area of the PApplet ?
Thanks for any suggestion.
Regards
Lawrence
I am trying to draw a picture in the "setup" method of a PApplet and then add (or embed) the PApplet into a JFrame. I have used "noLoop" in the last line of "setup" and have not used the "draw" method (I leave it blank). I have used the same size for the PApplet and the JFrame. However, when the JFrame is displayed, only a blank picture is shown on the PApplet's drawing area. The drawing area keeps blank until I perform an initial mouse click on this area. The drawing area then shows the blue rectangle correctly (but just after an initial mouse click).
The code snippet of the PApplet's program (in Java) is shown below :
public void setup() {
size(500, 500, P2D);
drawImpl();
// do something else not related to drawing
noLoop();
}
public void drawImpl() {
stroke(50);
fill(0,0,255);
translate(0, 0);
rect(0,0,30,30);
}
It seems that the blue rectangle is drawn normally in the PApplet's drawing area but Java has just not painted the PApplet's drawing area initially.
Is there any way that I can put some Java codes into the PApplet's program or the JFrame's program to trigger the initial painting of the drawing area of the PApplet ?
Thanks for any suggestion.
Regards
Lawrence
1