Since JavaOne I have decided to spend some time experimenting with JavaFX and Java 8 via the early bird release. The main new feature that I wished to experiment with was the printing api being added to JavaFX in this version. So far I have had very little to do with JavaFX so some of the things I have found and my opinions will not be new to those who have been using it for awhile, although there may be something new to you in my thoughts of some of the new things in Java 8.

So first off I should talk about setting up the new release. First I downloaded and installed the early bird release and began following some basic instructions that would give me a copy of eclipse (my preferred IDE) with beta 1.8 support. What I had seemed to work fine for the new javaFX api but the IDE did not recognize lambda expressions. For this reason I decided to give Netbeans 7.4 a try*.

Having already installed the early bird release, setting up the Netbeans 7.4 was incredibly easy, during installation I just had to point the IDE to the 1.8 JDK and it was set up and working. After trying some examples I found that Netbeans had support for lambda expressions and the expanded JavaFX api.

First thing I did was set up a simple printing example using the example code found in the JavaFX Printer docs page.

Node node = new Circle(100, 200, 200); PrinterJob job = PrinterJob.createPrinterJob(); if (job != null) { boolean success = job.printPage(node); if (success) { job.endJob(); } }

I must admit I like the idea behind the printing. Once you have created a node you only need to pass it to the printer and it can be printed. This means that once you have, for instance, got your pdf page drawn onto a node, in order to print a page all you need to do is use a PrinterJob to print the page. This is nice a simple.

There are down sides as well. The node being printed should not be altering during the printing otherwise the output image can be affected. For this reason it is recommended that any nodes being printed should not b altered. It seems the safest way to print would be make a duplicate of the node to be printed so we have a copy to print with and still allow the onscreen copies to be modified.

 

*Since trying NetBeans I have found that Eclipse appears to have some support for lambda expressions and now I believe I may have accidentally acquired an older beta version which may explain my issues when trying to get things up and running.

for more articles on javafx please visit http://blog.idrsolutions.com/2013/09/java-articles-index-understanding-the-world-of-java-and-java-fx/