cljfx

hairfire 2022-02-03T18:49:47.511669Z

Does anyone know of a cljfx example that renders an image from a resources directory?

phronmophobic 2022-02-03T18:57:16.235739Z

if you use ( fname) to get a url, you can pass that to something like https://github.com/phronmophobic/membrane/blob/master/src/membrane/cljfx.clj#L54 to create an javafx.scene.image.Image. You can then draw the image like https://github.com/phronmophobic/membrane/blob/master/src/membrane/cljfx.clj#L571

👍 1
hairfire 2022-02-03T20:42:48.950169Z

Here: https://clojurians.slack.com/archives/CGHHJNENB/p1589214377102900 @vlaaad mentions the :image prop of :fx/type :image-view can load resources from the class path. When I set the :url prop value to (http://clojure.java.io/resource "logo.png") I get this exception java.lang.ClassCastException: class java.net.URL cannot be cast to class java.lang.String (java.net.URL and java.lang.String are in module java.base of loader 'bootstrap').

hairfire 2022-02-03T21:24:33.810159Z

This seems to work:

hairfire 2022-02-03T21:24:44.590559Z

(defn resource-image [{:keys [resource-file]}]
  {:fx/type :image-view
   :image   (str ( resource-file))})

👍 1
phronmophobic 2022-02-03T21:31:25.501219Z

If you're deploying as a jar, it might be worth double checking if it still works when you jar your application. There are sometimes differences in behavior between file based resources and resources included in the jar.

✔️ 1