On 6/8/22 11:34 AM, Tobias Oelgarte wrote:

I don't know if there is an common event available in the Java2D backend to detect added/removed printers directly. So far i could not see anything like that.


I am referring to windows native code we have in Java 2D.
It is completely invisible at the API level of Java 2D.

Every PrintService instance should implement the equals() [1] method to determine uniqueness. This could be used to compare/intersect the observable set of printers hold by javafx.print.Printer#getAllPrinters() against the array of PrintService instances exposed by PrintServiceLookup.getPrintServices(...). That way it should be possible to detect if a printer was removed or added. It could also be used to update the default printer property (on access and/or periodically).


Well yes, there's got to be a comparison.  No one said "I don't know what to do here" ..


-phil.

[1] https://docs.oracle.com/en/java/javase/18/docs/api/java.desktop/javax/print/PrintService.html#equals(java.lang.Object)

On 07.06.22 21:44, Philip Race wrote:
Ahem .. well .. I guess we (I) forgot to get back to that.

Since the current implementation on Windows wraps the Java 2D printing code and it registers with windows to be told about changes in printers then the calls being made in the method with that comment would (well, should) provide
the updated printers ..

The comment was (I think) referring to the need to know when there was actually
a change there to avoid perpetual re-creation.

If the 2D side is working as expected I'll see if there's something I can do along the lines of a quick check every time that the number of underlying printers is the same and then if not it is worthwhile,
coupled with a refresh every 2 minutes so it should never get too stale.

-phil.

On 6/7/22 11:39 AM, Tobias Oelgarte wrote:
Is there some way to update the ObservableSet of Printers once the Application is running? Calling Printer.getAllPrinters() always returns the same OberservableSet and it does not change - ever. [1]

We have an JavaFx based application running under Windows 10/11 that is used to print on wireless printers, that are not always available. Having to restart the the application every time a printer goes away or comes available is a serious pain for the users.

Is there any kind of workaround?

I doubt it will be fixed in the near future, since this comment is from 6 years ago [2]:

    // This is static. Eventually I want it to be dynamic, but first
    // it needs to be enhanced to only create new instances where
    // there really has been a change, which will be rare.

[1] https://stackoverflow.com/questions/38470568/javafx-doesnt-detect-changes-of-available-printers

[2] https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/java/com/sun/prism/j2d/PrismPrintPipeline.java#L99


Reply via email to