B4J Question [B4J][B4XPages]Trouble getting jfx8Print dialogs to work

DaleA

Member
I have been trying to get the print dialogs to work in my app. I'm using simple code to call the dialog but as soon as I do I get an Unexpected Event error. The code below is what I've tried. I've also tried actually utilizing the Boolean Return and declaring and initializing a Form to use instead of Null.
B4X:
Dim pj As PrinterJob = PrinterJob_Static.CreatePrinterJob
pj.ShowPageSetupDialog(Null)
If the whole thing were innocuous I wouldn't mind too much but when I close the dialog it also closes the app, which isn't what I want.

Here's the stack trace:
B4X:
Unexpected event (missing RaiseSynchronousEvents): mainform_focuschanged
java.lang.Exception: Stack trace
    at java.base/java.lang.Thread.dumpStack(Thread.java:1387)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:199)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:233)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:201)
    at javafx.graphics/com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:509)
    at javafx.graphics/com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:591)
    at javafx.graphics/com.sun.prism.j2d.print.J2DPrinterJob.showPageDialogFromNestedLoop(J2DPrinterJob.java:316)
    at javafx.graphics/com.sun.prism.j2d.print.J2DPrinterJob.showPageDialog(J2DPrinterJob.java:285)
    at javafx.graphics/javafx.print.PrinterJob.showPageSetupDialog(PrinterJob.java:344)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4j.example.printerjob._showpagesetupdialog(printerjob.java:145)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:676)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
    at b4j.example.b4xmainpage._gogetprinters(b4xmainpage.java:659)
    at b4j.example.b4xmainpage._pbok_click(b4xmainpage.java:1082)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:233)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
It's probably something simple but I haven't been able to get a grasp on it so any help would be appreciated.
 

DaleA

Member
I can't ignore it since something is crashing the app and I'm lost as to what is going wrong. So here is a test app along with a stack trace so maybe someone can determine the cause and solution.

Thanks for any help on this.
 

Attachments

  • PrinterTest2.zip
    189 KB · Views: 277
Upvote 0

DaleA

Member
If I run it in Release mode it seems to work okay or, at least, doesn't terminate prematurely. To me, that implies that there is a problem with Debug mode which, since break points are ignored in Release mode, would make debugging print routines rather difficult.
 
Upvote 0

DaleA

Member
Ok, that leads me to the (apparent) solution. I added these 2 lines to the PrinterJob module in the JFX8Printer source:
B4X:
#RaisesSynchronousEvents: ShowPageSetupDialog
#RaisesSynchronousEvents: ShowPrintDialog
After I rebuilt the library, the crashes in Debug mode disappeared.

(Thanks to @stevel05 for posting the source so long ago.)
 
Upvote 0
Top