0

我正在开发一个小程序。我想使用 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) {
}

问题是它不起作用。我什么都看不见。你有什么主意吗?

4

1 回答 1

0

Maybe it's too late to answer, but...

Try to add this line below to your init()

getContentPane().add(jfxPanel);
于 2013-11-05T18:28:24.023 回答