使用JavaFX Java小程序 [英] Java applet using JavaFx

查看:1417
本文介绍了使用JavaFX Java小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个小程序。我想使用JavaFx的创建控件。目前,我使用的是JFXPanel。这里是code:

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...

尝试添加下面这行到你的init()

Try to add this line below to your init()

getContentPane().add(jfxPanel);

这篇关于使用JavaFX Java小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆