How to embed Piccolo2D
canvas inside JavaFX
?
I thought it should work via SwingNode, since Piccolo
has Swing
control named PCanvas.
This approach works with Swing:
public static void main(String[] args) {
PPath ellipse = PPath.createEllipse(100,100,400,200);
PCanvas canvas = new PCanvas();
canvas.getLayer().addChild(ellipse);
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.add(canvas, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setLocation(0, 0);
frame.setTitle("PCanvas_Try01");
frame.setVisible(true);
}
but this doesn't work with JavaFX
:
@Override
public void start(Stage stage) throws Exception {
PPath ellipse = PPath.createEllipse(100, 100, 400, 200);
PCanvas canvas = new PCanvas();
canvas.getLayer().addChild(ellipse);
SwingNode swingNode = new SwingNode();
swingNode.setContent(canvas);
Group group = new Group();
group.getChildren().add(swingNode);
Scene scene = new Scene(group);
stage.setTitle("PCanvas_Try02");
stage.setScene(scene);
stage.show();
}