Java Reference
In-Depth Information
In this example, a TextArea node is constructed, and then it is sent to a printer
when the button is clicked. The button in the application is bound to a method, which is
identified as print() . The print() method accepts a JavaFX node as the first ar-
gument and a Printer as the second argument. The Printer argument is the print-
er that represents the destination. To obtain the default operating system printer, issue
the following command, as shown in the example:
Printer.getDefaultPrinter();
A PrinterJob must be constructed before the JavaFX node can be sent to it, and
to do so, you call upon the PrinterJob.createPrinterJob() method. Once
the PrinterJob instance is created, you set the destination printer by passing the
Printer argument to the job.setPrinter() method. Finally, call the
job.printPage() method, passing the node to be printed.
To learn more about using the Print API, and to see a more detailed example, refer
to Recipe 14-17.
Scripting
The Java platform has had support for embedding and/or executing JavaScript files
since the release of Java 1.6, and the JavaScript engine was Rhino. The Rhino engine
served us well for years, but now an updated JavaScript engine named Nashorn has
entered the scene. The Nashorn engine brings with it many updates, including support
for the ECMAScript-262 Edition 5.1 language specification, a new command-line util-
ity for interactive interpretation or JavaScript file execution, and full access to the
JavaFX 8 API.
This chapter provides a couple of examples to get started using Nashorn. For more
information, see Chapter 18 , which is dedicated to the new JavaScript engine.
2-12.
Embedding
JavaScript
in
Your
Java Application
Problem
Search WWH ::




Custom Search