Java Reference
In-Depth Information
Scene scene = SceneBuilder . create ().
width ( 360 ). height ( 288 ).
root ( root ).
fill ( Color . WHITE ).
build ();
primaryStage . setScene ( scene );
primaryStage . show ();
}
}
Printing in Java
Problem
You need to generate hardcopy or a print-formatted output stream.
Solution
Use the javax.print printing service.
Discussion
The Java Printing Service API allows you to communicate with operating system-defined
print services. The basic steps are:
1. Obtain a DocFlavor for the kind of data you want to print.
2. Create an AttributeSet and fill in attributes such as paper size.
3. Look up a PrintService that can handle the job implied by the two objects just
defined.
4. Create a PrintJob from the PrintService .
5. Call the PrintJob 's print() method.
The data you send will be paginated by the printer service, so it can be any input stream that
would normally be acceptable for printing. In this case, I just send a small text file, and con-
firm that it shows up in my print queue and prints successfully.
Search WWH ::




Custom Search