If you'd like to give feedback on this post, please comment via the FXGraphics2D forum. Here is a screenshot (we encourage you to download the code and try it out live, particularly to see the tooltip and mouse event support):įaced with the problem of supporting JFreeChart and Orson Charts users wishing to migrate to JavaFX, we've created FXGraphics2D, a small, fast, elegant and free solution that bridges the divide between Java2D and JavaFX. The Orson Charts demo is larger and more interactive than what we have for JFreeChart so far. The screenshot from the JFreeChart demo (with source code here) appears above. Enter the project details like project name and click Finish. The following Pop-up window will be opened. Click on new and select Java project from the various types of options given in the list. Just click on the file icon appeared at the top left corner of the eclipse screen. There are a couple of demos included with the project on GitHub (one for JFreeChart and one for Orson Charts). Exporting JavaFX jar files to the Java Project. Now with our first public release, we are looking forward to feedback from a diverse range of users. So far in our testing, the code performs well and generates high-quality output. The code is small, fast, free (under a very liberal BSD-style license), and available now on GitHub. We've previously implemented the Graphics2D API targetting SVG output ( JFreeSVG) and PDF ( OrsonPDF) with great results, so we decided that a new Graphics2D implementation targetting the JavaFX Canvas would very likely solve our problem, minimising the disruption to our code, our clients' code, and also the cost of supporting both Java2D/Swing and JavaFX going forward.įXGraphics2D is our shiny new bridge class that maps Java2D drawing calls directly to the equivalent JavaFX Canvas API methods. NetBeans IDE opens an FXML project that includes the code for a basic Hello World application. Name the project FXMLExample and click Finish. In the JavaFX application category, choose JavaFX FXML Application. Read on to find out how we did it, and in the process future-proofed JFreeChart and Orson Charts (and maybe your code too). Your first task is to set up a JavaFX FXML project in NetBeans IDE: From the File menu, choose New Project. There exists a JavaFX Canvas component which can be used to "draw" vector output in the same way as you do with Java2D but, unfortunately, Oracle chose not to provide a Graphics2D API for this component, instead opting for an API that is roughly equivalent to that used by the HTML5 Canvas. For our clients already making the move to JavaFX, we want to make it as easy as possible for them to continue using JFreeChart and Orson Charts, and avoid having to significantly rework their code that produces charts and reports.but how? Java2D is a great technology that isn't going away but, as everyone knows, the future of Java desktop development is JavaFX. Here at Object Refinery we have built two products, JFreeChart and Orson Charts, that rely heavily on Java2D, specifically the Graphics2D API. by David Gilbert / in Java Migrating Java2D Code to JavaFX Overview
0 Comments
Leave a Reply. |