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();
node.getChildren().add(vb);
for(inti=0;i<100;i++){
    vb.getChildren().add(new Button("Button-"+i));
}
System.out.println("EXPORT:"+node);
PrinterJob job = PrinterJob.createPrinterJob();
boolean doPrint=job.showPrintDialog(FBEApp.window);
if(doPrint){
    System.out.println("Print Run";
    job.printPage(node);
} else {
    System.out.println("Cancel Print";
}
System.out.println("----");

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/javafx.graphics.jar) 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

environment
JRE...javaSE-11
IDE...eclipse
javafx...11.0.2

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.

See: https://docs.microsoft.com/ja-jp/azure/developer/java/fundamentals/transition-from-java-8-to-java-11

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.