This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-01
Channels
- # announcements (8)
- # aws (8)
- # babashka (21)
- # beginners (125)
- # calva (12)
- # cider (10)
- # circleci (29)
- # clara (6)
- # clj-kondo (34)
- # cljdoc (3)
- # cljfx (65)
- # cljs-dev (18)
- # clojure (38)
- # clojure-australia (4)
- # clojure-berlin (5)
- # clojure-czech (2)
- # clojure-dev (15)
- # clojure-europe (22)
- # clojure-nl (3)
- # clojure-uk (31)
- # clojuredesign-podcast (7)
- # clojurescript (87)
- # code-reviews (1)
- # conjure (3)
- # cursive (2)
- # data-science (1)
- # datalog (1)
- # datomic (36)
- # emacs (12)
- # events (1)
- # fulcro (3)
- # graalvm (68)
- # instaparse (2)
- # jackdaw (2)
- # jobs (2)
- # leiningen (8)
- # luminus (2)
- # nrepl (31)
- # pedestal (44)
- # releases (1)
- # remote-jobs (6)
- # shadow-cljs (4)
- # spacemacs (4)
- # sql (13)
- # tools-deps (56)
- # uncomplicate (4)
- # xtdb (40)
- # yada (11)
Unfortunately, I did not find information in the examples or in the source code, so I will ask.
Is it possible to fire several events at once? I mean something like :dispatch-n
in re-frame
@huxley yep, possible: effects are treated as a collection of tuples, it doesn’t have to be a map, e.g. [[:dispatch ...] [:dispatch ...]]
I don’t think there are code examples, just return a coll of tuples instead of a map in event handler 🙂
there are only examples returning maps. e.g. https://github.com/cljfx/cljfx/blob/master/examples/e18_pure_event_handling/events.clj#L15-L20
I did something similar, but I thought that maybe there is a more obvious solution, for example something like that.
{:fx/type :button
:text "button"
:on-action [{:event/type :evt-1}
{:event/type :evt-2}
{:event/type :evt-3}]}
ah, no, there is nothing like that unfortunately, you can only have a single event in description
I have an issue to make event handlers more free-form: https://github.com/cljfx/cljfx/issues/48
As documented in https://github.com/cljfx/cljfx#aot-compilation-is-complicated, the classes from javafx.scene.control require JavaFX runtime to be running by accessing it in Control's static initializer. I've encountered a variation on this issue that manifests itself in a nREPL session. After initializing the toolkit, any code running on the Javafx Application Thread that references a control throws an error.
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: Could not initialize class javafx.scene.control.Label
The following code block runs fine because it doesn't reference a control.
(let [stage (Stage.)
stack-pane (StackPane.)
scene (Scene. stack-pane 640 480)]
(.setScene stage scene)
(.show stage))
An empty window appears.
However, the following code block throws the aforementioned error because it references a control.
(let [stage (Stage.)
label (Label. "Hello")
stack-pane (StackPane. (into-array Node [^Label label]))
scene (Scene. stack-pane 640 480)]
(.setScene stage scene)
(.show stage))
To be clear, this issue has nothing to do with cljfx. Most likely it is a problem with nREPL and its class loading. The problem doesn't appear with inf-clojure either. I'm asking it here in case this resonates with someone.java 11? call (javafx.application.Platform/startup #())
before importing classes from javafx.scene.control
package
The import statement are in the ns declaration, the platform initialization is a top-level definition.
hm, I would guess this is the problem — JavaFX runtime has to be started before javafx.scene.control.* classes are imported
I tried at the REPL, initialized the JavaFX runtime, then imported the control at the REPL, still the same error.
hmm, actually just running (import 'javafx.scene.control.Label)
does not fail in a freshly-started repl with JavaFX on the classpath
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: Could not initialize class javafx.scene.control.Label
at caonima.repl$foo$f__15007__auto____15021.invoke(repl.clj:35)
at clojure.lang.AFn.run(AFn.java:22)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:832)
No. It's definitely a nREPL specific problem, just asking if anyone has seen this before.
Hello, i want to create menu-item to use file chooser, so i modified the root-view of https://github.com/cljfx/cljfx/blob/master/examples/e33_file_chooser.clj But for the menu-item it gave me
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: No matching field found: getScene for class javafx.scene.control.MenuItem
(defn root-view [{:keys [image-path content]}]
{:fx/type :stage
:title "Textual file viewer"
:showing true
:width 800
:height 600
:scene {:fx/type :scene
:root {:fx/type :v-box
:children [{:fx/type :menu-bar
:menus [{:fx/type :menu
:text "File"
:items [{:fx/type :menu-item
:text "Open image ..."
:on-action {::event ::open-image}}]}]}
;; The button works but not for the menu above
{:fx/type :h-box
:spacing 15
:alignment :center-left
:children [{:fx/type :button
:text "Open file..."
:on-action {::event ::open-image}}
{:fx/type :label
:text (str image-path)}]}]}}})
@danielsz just in case — the problems with JavaFX initialization and controls I had had to do with this code in Control static initializer: https://github.com/openjdk/jfx/blob/d10f948ee7380ac73bc4e2d5bff1caba50fe00a8/modules/javafx.controls/src/main/java/javafx/scene/control/Control.java#L98-L100
Yes, that is indeed why the JavaFx runtime needs to be running when compiling those classes. You've explained it nicely in the README. I thank you for that. Have you noticed what happens https://github.com/openjdk/jfx/blob/d10f948ee7380ac73bc4e2d5bff1caba50fe00a8/modules/javafx.controls/src/main/java/javafx/scene/control/Control.java#L119 in that same class? It's a class loading hack. nREPL does its own class loading hacks and I suspect they don't see eye to eye.
My super basic interop throws this class not found error. And the maddening thing is: not all the time.
I'll take this opportunity to congratulate you on the work. I've been reading the source code. Very elegant. Kudos!
@raefaldhiamartya can you share the whole stacktrace?
ah, there is this call in the example code https://github.com/cljfx/cljfx/blob/master/examples/e33_file_chooser.clj#L12-L17
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: No matching field found: getScene for class javafx.scene.control.MenuItem
at clojure.lang.Reflector.getInstanceField(Reflector.java:397)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:440)
at clojure.io.github.raefaldhia.image_processing.core$eval17490$fn__17492.invoke(core.clj:13)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at cljfx.event_handler$wrap_co_effects$fn__13793.invoke(event_handler.clj:10)
at cljfx.event_handler$wrap_effects$dispatch_sync_BANG___13806.invoke(event_handler.clj:27)
at cljfx.event_handler$wrap_effects$dispatch_sync_BANG___13806.invoke(event_handler.clj:25)
at cljfx.lifecycle$make_handler_fn$fn__13457.invoke(lifecycle.clj:128)
at cljfx.coerce$event_handler$reify__13022.handle(coerce.clj:135)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.control.MenuItem.fire(MenuItem.java:459)
at com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1380)
at com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.lambda$createChildren$12(ContextMenuContent.java:1333)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3890)
at javafx.scene.Scene.processMouseEvent(Scene.java:1885)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2618)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
at com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at com.sun.glass.ui.View.notifyMouse(View.java:942)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:834)
Looks like MenuItem does not have .getScene
method that is called on an event target by the handler