custom controls: printing

Tom Eugelink tbee at
Thu Jan 29 06:23:45 UTC 2015

Ok, I see my question is not quite clear: I'm not looking for how to print, I am trying to figure out how to properly implement printing on a custom control, more specifically JFxtras' Agenda. Agenda has the same problem as the more recognizable usecase of a spreadsheet: it uses a scrollpane in its skin, so when taking a screenshot this scrollpane limits what is captured, but when printing -like a spreadsheet- I need all the data.

So first I was trying to grasp how printing in JavaFX works conceptually, but from what I'm decuding so far this is very limited and basically no more that screen capturing. Correct?


On 29-1-2015 05:53, Phil Race wrote:
> That example is not great as it picked the one node type that knows how to do
> something special with printing and completely overlooks it.
> The print(Node) method it provides can print any node type but it is scaling
> it to fit on a single side of paper. That's not ideal for a huge spreadsheet/table
> as you won't be able to read the output without a microscope.
> I was pointing to the method on webengine that you mention last below
> as the one you should use and the example does not use that anywhere.
> To get  proper pagination you need to explicitly call the WebEngine.print(PrinterJob) method
> -phil.
> On 1/27/15 10:22 PM, Tom Eugelink wrote:
>> Ok, so looking at some examples like
>> where PrintJob is let lose on a node, JavaFX's PrintJob will either use the screen rendering or -if present- call: public void print(PrinterJob job)
>> Correct?
>> Tom
>> On 28-1-2015 02:43, Phil Race wrote:
>>> On 1/27/15 4:08 PM, Tom Eugelink wrote:
>>>> Do I need to do something special to support printing of custom controls? The use case is that on screen a spreadsheet can be shown in a scrollpane, but when printing the whole spreadsheet should be printed. 
>>> Being a 'custom' control doesn't really make a difference here.
>>> The same would apply if you wanted to print one of the built-in controls
>>> that is in a scroll pane or otherwise not likely to fit on a page.
>>> Spreadsheets, like TableView, TextArea and the like will need
>>> to have their data laid out for the printer by the application.
>>> In practice this means starting with the data contained in
>>> the spreadsheet and iterating over it printing as much as fits
>>> on each page in what ever way you want.
>>> I am sure that something that can handle this this would
>>> make a nice add-on to to the core API but it was not something
>>> that was considered appropriate to be part of FX core.
>>> We expected reporting packages to pop up from 3rd parties
>>> The exception to this is HtmlEditor / WebEngine where you
>>> cannot reasonably expect the application or such a package
>>> to know how to properly print the data (HTML and other web content)
>>> Hence that has a method to print its content to a PrinterJob
>>> So one possibility for you is to throw your data into HTML table syntax, load
>>> it into a web node and print that.
>>> -phil.

More information about the openjfx-dev mailing list