there is this JFrame
containg a JPanel
containing a processing
sketch. The code looks something like this:
import javax.swing.JFrame;
import javax.swing.JPanel;
import processing.core.PApplet;
public class TestCase {
public static void main(String[] args) {
ProcessingFrame pFrame = new ProcessingFrame();
pFrame.setVisible(true);
}
}
@SuppressWarnings("serial")
public class ProcessingFrame extends JFrame{
public ProcessingFrame(){
this.setSize(600, 400);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
ProcessingSketch pSketch = new ProcessingSketch();
panel.add(pSketch);
this.add(panel);
pSketch.init();
this.setVisible(true);
}
}
public class ProcessingSketch extends PApplet{
public ProcessingSketch(){
//...
}
public void setup(){
size(600, 400);
background(200);
}
public void draw(){
rect(250,100,100,200);
}
}
Too often (about 50%) the panel
and/or sketch
is not rendered to the appropriate location. Sometimes they are just about half of the frame size off to the right, sometimes I see just the bottom of the sketch in the frame.
After I resize the frame with the mouse, everything looks fine. I would like to set the JFrame to undecorated
, but there is no way to resize the windows to put everything into place.
This is what I tried to solve that:
JFrame.repaint()
as suggested here: Java items appear only after the window is resize. - No effect.I thought i could just resize the window by hand and then change to
undecorated
. Following the answer of this question: Modifying a JFrame from within a Listener. But the processing sketch crashes because I have todispose
the JFrame.
Any other ideas?