jfx java,使用JavaFX Java小程序

本文档描述了在开发一个applet时遇到的问题,即使用JavaFX创建控件但无法显示。作者提供了相关的代码片段,其中包含了JFXPanel、Canvas、Scene和BorderPane的初始化。问题在于内容没有正确显示。解决方案建议在init方法中添加一行代码,将JFXPanel添加到contentPane中。
摘要由CSDN通过智能技术生成

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值