Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining JavaFX and Scala - is it possible?

Tags:

scala

javafx

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?

like image 586
helpermethod Avatar asked Mar 02 '10 20:03

helpermethod


3 Answers

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.

like image 99
oxbow_lakes Avatar answered Sep 25 '22 08:09

oxbow_lakes


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.

like image 34
Peter Becker Avatar answered Sep 22 '22 08:09

Peter Becker


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.

like image 44
Brian Agnew Avatar answered Sep 22 '22 08:09

Brian Agnew