no, use val f = find<MyFragment>()
# tornadofx
c
no, use val f = find<MyFragment>()
s
Thank you for the info Carl! A few questions, if you aren't too busy and don't mind. Could you explain the difference between doing it with
find
and just instantiating it like I was doing before? And also I am getting an error when trying to use
find
with my new code:
Copy code
fun createChannelFragment(c: SystemInput, group: Group?): Node {
        val inputFragment = find<InputFragment>(c, group)
        inputFragment.root.add(WorkspaceGraph(inputFragment).root)
        return inputFragment.root
    }
It says I can't call any of the functions with the arguments supplied 😞
I'm definitely doing something wrong while trying to pass these values into the constructor
h
You cant pass them in the constructor; instead set them on the fragment once found
inject a ViewModel in the Fragment
Or you can pass them to
InputFragment
like so:
Copy code
find<InputFragment>(mapOf(InputFragment::systemInput to c, InputFragment::group to group))
Assuming
InputFragment
has properties named
systemInput
and
group
.
s
Hmm. Mapping the properties that way is giving me a new error.
Copy code
Feb 28, 2019 3:06:40 AM tornadofx.DefaultErrorHandler uncaughtException
SEVERE: Uncaught error
java.lang.InstantiationException: org.tenkiv.labrat.components.fragments.InputFragment
	at java.lang.Class.newInstance(Class.java:427)
	at tornadofx.FXKt.find(FX.kt:451)
Copy code
val inputFragment = find<InputFragment>(params = mapOf(InputFragment::input to c, InputFragment::group to group))
what I changed it to
class InputFragment(val input: SystemInput, val group: Group?) : Fragment()
that is the InputFragment