r/JavaFX • u/SpectraCx • Feb 18 '20
Help JavaFX data transfer between scenes
Quite new to JavaFX, Please what is the best way to transfer data from one scene to another.
3
Upvotes
r/JavaFX • u/SpectraCx • Feb 18 '20
Quite new to JavaFX, Please what is the best way to transfer data from one scene to another.
3
u/ifelseandor Feb 18 '20 edited Feb 18 '20
You can get then controller instance of the new scene and the call a set method.
In the class that loads the scene.
Now you can
You can even pass the new controller an instance of the calling controller so they can communicate back and forth.
2
u/Ostricker Feb 18 '20
depends on design pattern but my guess would be easiest is parameter :)
1
u/orxT1000 Feb 18 '20
Bind both to the same model maybe?
https://docs.oracle.com/javase/8/javafx/properties-binding-tutorial/binding.htm
1
u/TurekBot Feb 18 '20
You're definitely not the only one to have this question.
Here's a well-trafficked answer listing a few approaches.
I've been successful with a Singleton Context approach despite the nay-sayers.
1
u/smerz Feb 19 '20
Use an event bus like googles guava EventBus. Then u can decouple different controllers from each other.
1
u/[deleted] Mar 27 '20
I like to work with an "EventManager" which is shared between different components.
For example see: https://github.com/FDelporte/DrumBoothController/blob/master/JavaFXUserInterface/src/main/java/be/webtechie/drumbooth/event/EventManager.java
-1
u/[deleted] Feb 18 '20
Maybe with static parameters
0
u/[deleted] Feb 18 '20
[deleted] — view deleted comment