将 JFXPanel 添加到 JFrame。为什么它不起作用?
我正在尝试将 JFXPanel 添加到我的 JFrame 中。我正在使用 Netbeans 和 Netbeans 的 Swing GUI Builder。当我运行它时,我没有收到任何错误,并且 JFrame 已成功创建,但带有文本的 JFXPanel 没有出现。
这是我的代码:
public class TestingFX {
private static void initJFrame() {
NewJFrame frame = new NewJFrame();
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setVisible(true);
Platform.runLater(new Runnable() {
@Override
public void run() {
fxPanel.setScene(createScene());
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initJFrame();
}
});
}
public static Scene createScene() {
Text text = new Text("Hello World");
text.setFont(new Font(24));
text.setEffect(new Reflection());
BorderPane pane = new BorderPane();
pane.setCenter(text);
Scene scene = new Scene(pane);
return scene;
}
}
为什么它不起作用?我做错了什么吗?
I am trying to add a JFXPanel to my JFrame. I am using Netbeans and Netbeans' Swing GUI Builder. When I run it I do not get any errors and the JFrame is created successfully but the JFXPanel with the text does not appear.
Here is my code:
public class TestingFX {
private static void initJFrame() {
NewJFrame frame = new NewJFrame();
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setVisible(true);
Platform.runLater(new Runnable() {
@Override
public void run() {
fxPanel.setScene(createScene());
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initJFrame();
}
});
}
public static Scene createScene() {
Text text = new Text("Hello World");
text.setFont(new Font(24));
text.setEffect(new Reflection());
BorderPane pane = new BorderPane();
pane.setCenter(text);
Scene scene = new Scene(pane);
return scene;
}
}
Why is it not working? Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您应该阅读将JavaFX集成到Swing应用程序,然后重构相应地你的代码。
尝试
创建场景时,本示例假定您包含的代码有效。
Perhaps you should read Integrating JavaFX into Swing Applications, and then refactor your code accordingly.
Try
When creating a scene, this example assumes that the code you've included is valid.
我试图将 JFXPanel 添加到 JPanel,这解决了我的问题,也可能对您有帮助
I was trying to add JFXPanel to JPanel and this solved the problem for me, might help you as well