JavaFx Fails to Print

Asked 2 months ago, Updated 2 months ago, 6 views

In JavaFx, I used PrinterJob to execute the following code, but an error (?) appeared and I couldn't print well (I couldn't open it in Google Chrome).
Please tell me the cause and solution.

Code executed

AnchorPane node=newAnchorPane();
VBox vb = new VBox();
    vb.getChildren().add(new Button("Button-"+i));
PrinterJob job = PrinterJob.createPrinterJob();
boolean doPrint=job.showPrintDialog(FBEApp.window);
    System.out.println("Print Run";
} else {
    System.out.println("Cancel Print";

Console View

EXPORT: [email protected]
print execution
WARNING—Animal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.prism.j2d.J2DFontFactory(file:/**hide**javafx-sdk-11.0.2/lib/ to method sun.font.FontUtilities.getCompositeFontUIRource(java)
WARNING: Please consumer reporting this to the maintainers of com.sun.prism.j2d.J2DFontFactory
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING:All illegal access operations will be denied in a future release


java javafx printing

2022-09-30 11:41

1 Answers

Let's start with the contents of the error (not a warning).

I think the meaning is as follows.

An incorrect reflection from com.sun.prism.j2d.J2DFontFactory to sun.font.FontUtilities.getCompositeFontUIResource has occurred.If possible, please report to com.sun.prism.j2d.J2DFontFactory developer.Bad reflections will not work in full in the future, but now they act as "warns" by --illlegal-access=warn.

The warning was detailed on the Microsoft site.To quote.

We recommend that you configure the command-line option --illegal-access=warn. Java 11 generates a bad reflect access warning when accessing the JDK internal API using reflection. By default, warnings are issued only for the first rogue access. -- ilgal-access=warn generates a "warning" for each rogue reflex access. More cases will be found if the option is unauthorized access set to warn. However, many duplicate warnings are also displayed.
Once the application runs on Java 11, configure --illlegal-access=deny to mimic future Java runtime behavior. For Java 16 and later, the default value is --illlegal-access=deny.


Therefore, we recommend that you try the following conditions:

2022-09-30 11:41

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.