简体   繁体   English

在Swing应用程序中使用JavaFX图表

[英]Using JavaFX Chart in Swing Application

I have a traditional Java swing application (extends JFrame and has a main class) that uses JFreeCharts for some charting functionality. 我有一个传统的Java swing应用程序(扩展了JFrame并具有一个主类),该应用程序使用JFreeCharts来实现某些图表功能。 I have recently seen JavaFX and think these charts look alot refresher and will give my users a better experience. 我最近看过JavaFX,并认为这些图表看起来很新鲜,可以为我的用户带来更好的体验。 I wish to embed a JavaFX chart scene into a jInternalFrame (which in turn is called from my jDesktopPane). 我希望将JavaFX图表场景嵌入到jInternalFrame中(依次从我的jDesktopPane中调用它)。

I have followed a simple tutorial on how to create both a javafx application and a javafx chart but I am stuck on to how I get the scene inside my existing code. 我遵循了有关如何创建javafx应用程序和javafx图表的简单教程,但是我仍然坚持如何在现有代码中获得场景。 One example I have been through shows me how to achieve this but means converting my project to a javafx one which extends "application" class. 我经过的一个示例向我展示了如何实现此目标,但意味着将我的项目转换为扩展“应用程序”类的javafx项目。

How can I achieve what I want? 我怎样才能实现自己想要的? Is it not possible to keep my existing JFrame as the top level class and simply add a JFXPanel to my jinternalframe. 是否不可能将现有的JFrame保留为顶级类,而只是将JFXPanel添加到我的jinternalframe中。

Any help would be great, please note I have been through some tutorials and they require me to convert my project to javafx - I simply want a javafx scene in my existing swing app. 任何帮助都将非常有用,请注意,我已经看过一些教程,并且它们要求我将项目转换为javafx-我只是想在现有的swing应用程序中使用javafx场景。

Many thanks, 非常感谢,

You don't need to convert your Swing application to a JavaFX application. 您无需将Swing应用程序转换为JavaFX应用程序。 You can place a JavaFX Chart in a JFXPanel which may be placed in a Swing component. 您可以将JavaFX Chart放置在JFXPanel中 ,该JFXPanel可以放置在Swing组件中。 The javadoc I linked includes sample code for embedding a JavaFX node in a Swing application. 我链接的javadoc包括用于将JavaFX节点嵌入到Swing应用程序中的示例代码。

Review the official JavaFX for Swing Developers tutorial trail from Oracle. 查看Oracle的官方JavaFX for Swing开发人员教程。

Also look at the Embedding JavaFX in Swing sample of SwingInterop for embedding a chart in a Swing application. 还要查看SwingInterop Swing示例中的“ 在Swing中嵌入JavaFX”,以在Swing应用程序中嵌入图表。 The sample is provided by Oracle under the BSD open source license so that you can use it in your application. 该示例由Oracle根据BSD开源许可证提供,因此您可以在应用程序中使用它。

Despite all this, my advice, unless it is a large, existing Swing code base that you just want to use a couple of JavaFX features in, is to write your application as a pure JavaFX application rather than a mixed Swing/JavaFX application. 尽管如此,我的建议是将应用程序编写为纯JavaFX应用程序,而不是混合的Swing / JavaFX应用程序,除非您只是想在其中使用几个JavaFX功能而使用的庞大的现有Swing代码库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM