Fork me on GitHub
#cljfx
<
2021-12-10
>
jvtrigueros17:12:33

Is there a way to get a reference to the top level Stage in an event handler? The :on-action event contains the key :fx/event which is an ActionEvent. With this object I can sometimes get all the way to the top and get the top most Window, but in this case I have a MenuItem and don’t see a way to obtain a reference to the Stage. This is the code this is based on https://github.com/cljfx/cljfx/pull/40#issuecomment-544256262

thom20:12:46

I've used ext-on-instance-lifecycle in the past to catch a reference to the top level stage and store it in a promise.

jvtrigueros05:12:25

I’ll look into that! Might have to do this as a workaround.

thom07:12:19

Would love to hear back if there's something simpler. Seems likely you could just navigate up the Node tree but that doesn't feel more elegant.

vlaaad20:12:54

when looking in event, did you check both .getSource and .getTarget if it's possible to reach stage?

jvtrigueros05:12:34

IIRC both source and target give me a MenuItem. From the MenuItem I don’t see a way back to reach the parent stage. I tried getParent on it and I reach the Menu which is a dead end. On mobile, excuse formatting