Is it possible to use them in conjunction? It would be nice to write the GUI in JavaFX and define the business logic in Scala. Any ideas?
Asked
Active
Viewed 2,055 times
3 Answers
11
If it's just a more script-like UI definition code that you want, I'd urge you to look at Scala-Swing as it lets you write code like:
Scala Swing
val f = new Frame {
title = "My Scala Swing Frame"
width = 300
height = 300
content = new BoxPanel
content += new TextArea {
font = new Font("tahoma", 22, Font.PLAIN)
textAlignment = Center
text = "Welcome to\nScala Swing"
}
}
Compare that to this JavaFX example
Java FX
Stage {
title: "My First JavaFX Sphere"
scene: Scene {
width: 300
height: 300
content: [
Text {
font: Font { size: 22 }
x: 20, y: 90
textAlignment: TextAlignment.CENTER
content:"Welcome to \nJavaFX World"
}
]
}
}
Of course, there may be other features of JavaFX beyond this code-style which you are looking for.

oxbow_lakes
- 133,303
- 56
- 317
- 449
-
2Cool, didn't know something like that existed. Does it also support features like binding? – helpermethod Mar 03 '10 at 18:06
-
When I plug this example into the REPL (after importing swing._) it tells me `error: not found: value width`, and same for `height` and `content`... what am I doing wrong? – Luigi Plinge Jul 14 '11 at 15:50
9
For what it is worth this long after the original question: I just found http://code.google.com/p/scalafx/ offering Scala to JavaFX 2.0 bindings.

Peter Becker
- 8,795
- 7
- 41
- 64
-
Did you get scalafx compiling, if so on which version / OS? Reason I'm asking is this: http://stackoverflow.com/questions/12917101/compiling-scalafx-for-java-7u7-that-contains-javafx-2-2-on-os-x – akauppi Oct 16 '12 at 15:11
7
Scala and JavaFX both run on the JVM, so there should be few problems integrating the two.
Pain points may involve converting between Scala and Java standard collections since the implementations are different (e.g. a Scala list is not a Java List) but that aside, there shouldn't be major issues.

Mnementh
- 50,487
- 48
- 148
- 202

Brian Agnew
- 268,207
- 37
- 334
- 440