I'm developing an applet. I want to use JavaFx to create the controls. Currently, I'm using An JFXPanel. Here is the code:
private JFXPanel jfxPanel;
private Canvas canvas;
private Scene scene;
private BorderPane borderPane;
public void init() {
jfxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
@Override
public void run() {
jfxPanel.setScene(createScene());
add(jfxPanel);
}
});
}
public Scene createScene() {
borderPane = new BorderPane();
scene = new Scene(borderPane, 400, 800);
canvas = new Canvas();
canvas.getGraphicsContext2D().setFill(Color.RED);
borderPane.setCenter(canvas);
return scene;
}
public void paint(Graphics g) {
}
The problem is that it doesn't work. I can't see anything. Do you have any idea?
解决方案
Maybe it's too late to answer, but...
Try to add this line below to your init()
getContentPane().add(jfxPanel);