By suitable, I mean:
In no particular order.
Which GUI toolkits satisfy which conditions?
Scala has its own Swing library. This will use the standard Swing library under the hood but it has some nice additions and most notably, because it's made for Scala, it can be used in a much more concise way than the standard Swing library:
import swing._ object HelloWorld extends SimpleSwingApplication { def top = new MainFrame { title = "Hello, World!" contents = new Button { text = "Click Me!" } } }
See how nice and easy it is to set widget properties?
Except for the nicer syntax and the small additions (like the SimpleSwingApplication
class), I think the advantages and disadvantages are pretty much the same as with vanilla Swing.
Here's an Overview of Scala Swing.
ScalaFX is a mature wrapper around JavaFX 2. It is superficially similar to Scala Swing in some regards, but has some features that make it stand out:
Couplings to native graphics libraries - This means access to hardware acceleration and other goodies, but requires the JavaFX runtime to be installed on the system. It is included in most major distributions of Java 8. This also means it renders very well on the systems with which it's compatible.
Property bindings - This is the killer feature for me. Say that I have three elements: A
, B
, and C
. A
and B
are resizable, and C
is supposed to have a height which is the sum of the heights of A
and B
at all times. In Swing, this would involve writing a set of custom event listeners to perform this work. ScalaFX bindings lets you express this simply by using the property bind operator: C.height <== A.height + B.height
. This, among other features, makes for a very Scala-idiomatic feel.
JavaFX Scene Builder (in beta as of writing) is a WYSIWYG GUI editor (I haven't tried it, though).
Documentation is its weak point. Being a wrapper, it often refers back to the JavaFX documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With