Class Printer
public final class Printer
extends Object Printers may be enumerated and selected for use with a print job.
The configuration of the printer default settings are then used to populate the initial settings for a job.
Since the availability of printers may change during the execution of a program, due to administrative actions, a long running program which has cached a printer which has since been taken off-line, may create a job using that instance, but printing will fail.
- Since:
- JavaFX 8.0
Property Summary
| Type | Property | Description |
|---|---|---|
static ReadOnlyObjectProperty<Printer> | defaultPrinter | A read only object property representing the current default printer. |
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
static class | Printer.MarginType | The MarginType is used to determine the printable area of a PageLayout. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
PageLayout | createPageLayout(Paper paper,
PageOrientation orient,
double lMargin,
double rMargin,
double tMargin,
double bMargin) | Obtain a new PageLayout for this printer using the specified parameters. |
PageLayout | createPageLayout(Paper paper,
PageOrientation orient,
Printer.MarginType mType) | Obtain a new PageLayout instance for this printer using the specified parameters. |
static ReadOnlyObjectProperty<Printer> | defaultPrinterProperty() | A read only object property representing the current default printer. |
static ObservableSet<Printer> | getAllPrinters() | Retrieve the installed printers. |
PageLayout | getDefaultPageLayout() | Return the default page layout for this printer. |
static Printer | getDefaultPrinter() | Retrieve the default printer. |
String | getName() | Return the name used by the underlying system to identify the printer to users and/or applications. |
PrinterAttributes | getPrinterAttributes() | Retrieves the delegate object encapsulating the printer attributes and capabilities. |
Property Details
defaultPrinter
public static ReadOnlyObjectProperty<Printer> defaultPrinterProperty
- See Also:
getDefaultPrinter()
Method Details
getAllPrinters
public static ObservableSet<Printer> getAllPrinters()
Note: since printers may be installed, but offline, then the application may want to query the status of a printer before using it.
- Returns:
- may be null if there are no printers.
- Throws:
-
SecurityException- if the application does not have permission to browse printers.
defaultPrinterProperty
public static ReadOnlyObjectProperty<Printer> defaultPrinterProperty()
- See Also:
getDefaultPrinter()
getDefaultPrinter
public static Printer getDefaultPrinter()
The configuration of available printers may be dynamic. Consequently there is no guarantee that the result will be the same from call to call, but should change only as a result of the default changing in the environment of the application.
- Returns:
- default printer or null.
- Throws:
-
SecurityException- if the application does not have permission to browse printers.
getName
public String getName()
- Returns:
- printer name.
getPrinterAttributes
public PrinterAttributes getPrinterAttributes()
- Returns:
- printer attributes.
getDefaultPageLayout
public PageLayout getDefaultPageLayout()
- Returns:
- default page layout.
createPageLayout
public PageLayout createPageLayout(Paper paper, PageOrientation orient, Printer.MarginType mType)
- Parameters:
-
paper- The paper to use -
orient- The orientation to use -
mType- the margin type to use - Returns:
- PageLayout based on the specified parameters.
- Throws:
-
NullPointerException- if any of the parameters are null.
createPageLayout
public PageLayout createPageLayout(Paper paper, PageOrientation orient, double lMargin, double rMargin, double tMargin, double bMargin)
Margin values are specified in 1/72 of an inch points. Margins will be validated against the printer supported margins, and adjusted if necessary. This method is generally useful to a client that wants margins that are different (eg wider) than the default margins, such as 1" at top and bottom and 0.5" to the left and right.
A client that needs to know what margin values are legal should first obtain a PageLayout using the HARDWARE_MINIMUM margins.
If the printer cannot support the layout as specified, it will adjust the returned layout to a supported configuration
- Parameters:
-
paper- The paper to use -
orient- The orientation to use -
lMargin- the left margin to use in pts. -
rMargin- the right margin to use in pts. -
tMargin- the top margin to use in pts. -
bMargin- the bottom margin to use in pts. - Returns:
- PageLayout based on the specified parameters.
- Throws:
-
NullPointerException- if paper or orient are null. -
IllegalArgumentException- if any of the margins values are less than zero.
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.