我正在开发一个小程序。我想使用 JavaFx 创建控件。目前,我正在使用 An JFXPanel。这是代码:
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) {
}
问题是它不起作用。我什么都看不见。你有什么主意吗?