Is there some guide or walkthrough to building a Scala + JavaFX desktop application?
I\'m having hard time finding a good source and I am using IntelliJ IDEA as the
I was able to solve this problem in scala_swing much more satisfactorily because you could instantiate an instance with parameters then call main on it to start Swing later.
This solution allows parameters to be obtained in the FX application at the cost of using static var and possible other issues. One being that this is surely not multi-thread safe.
package hack
/**
* Created by WorkDay on 8/11/16.
*
* HelloTest shows a method which allows parameters to be passed
* into your javaFX application as it is started
* this allows it to be connected to non-FX code that existed before it.
*
* You could also pass a reference to the Application back
* into the non-FX code if needed.
*/
import javafx.application.Application
import javafx.scene.Scene
import javafx.scene.layout.StackPane
import javafx.stage.Stage
import javafx.scene.control.Label
case class Data(data: String)
object SomeOtherCode extends App {
HelloTest.launch(Data("brave"), Data("new"))
}
object HelloTest {
var data1: Data = _
var data2: Data = _
def launch(data1: Data, data2: Data) = {
HelloTest.data1 = data1
HelloTest.data2 = data2
Application.launch(classOf[HelloTest])
}
}
private class HelloTest extends Application {
val data1: Data = HelloTest.data1
val data2: Data = HelloTest.data2
override def start(primaryStage: Stage) {
primaryStage.setTitle("Sup!")
val root = new StackPane
root.getChildren.add(new Label(s"Hello ${data1.data} ${data2.data} world!"))
primaryStage.setScene(new Scene(root, 300, 300))
primaryStage.setX(0)
primaryStage.setY(0)
primaryStage.show()
}
}