I am looking for a way to print the contents of a JavaFX TableView. I understand that JavaFX doesn't have Printing capabillities just yet (what a disapointment). I have found some information about taking a screenshot of a WebView for example and print it as an image.
Is it possible to do something like that with a Table view. How to go about to handle multiple pages on tables with many data.
Thanks for your help
Java 8 includes printing capabilities for JavaFX. https://jdk8.java.net/download.html
The Java 8 printing features were implemented under RT-17383 Printing and function as described in @Asimaruk's answer.
You can do this if you can't use Java 8.
Use the JavaFX snapshot api, use SwingFXUtils to convert the JavaFX image to a BufferedImage, use Swing print methods to print the BufferedImage.
If you can't use Java 8, use the above snapshot method for each page, scrolling the table data between each snapshot.
Also see RT-17665 Make some UI controls support printing their content which is a request for a direct print api added to some controls (e.g. TableView), so you could right tableView.print() to print only the tableview and not an entire scene. This convenience API for printing has not currently been implemented but you can vote or comment on the related issue to indicate your interest in the feature.
Printing API appeared in fx8.0. And it can print nodes. You can create printer job with javafx.print.PrinterJob class. But it prints only region that fits to a printed page, and not the one that you on a screen. So you need to make your node fit page(scale, translate, etc) by hands. Here is simple printing example:
Snip the area you want
Resize according to A4 paper size and print
I have tried this . It first shows a page dialog window, then scales, translates and prints.