What is New in ScalaFX 1.0 Milestone 5

ScalaFX helps you simplify creation of JavaFX-based user interfaces in Scala. ScalaFX uses a simple, hierarchical pattern for creating new objects and building up the scene graph. ScalaFX supports full interoperability with Java and can run anywhere the Java Virtual Machine (JVM) and JavaFX2 are supported.
ScalaFX 1.0 M5 supports most of the JavaFX 2.2.25 functionality, (distributed with Java 1.7.0_u25).

Summary of Changes since Milestone 4

  • Major improvements to Chart’s API – charts can be created without need to use JavaFX type parameters and the same hierarchical build pattern as in the rest of ScalaFX.
  • Easier way to create, add and remove event handlers and event filters that handle more than one event.
  • New implicit conversions from color from tuples.
  • New wrapper for `VerticalDirection`.
  • Added several of new demos, improved a couple of the existing ones.
  • Several bug fixes, including issues 61, 66, 67 and 70.
  • Internal code cleanup and simplification.
  • Several improvements to build system, tests, upgrades to dependent libraries and SBT plugins.

New and Improved

Major improvements to chart’s API

The focus was on making the chart API easier to use, in particular, to remove to able to create charts without using JavaFX type parameters (Issue 79) and being able to use ScalaFX’s hierarchical build pattern (Issue 72). The improvements are illustrated in this complete example of creating an application that displays a Pie Chart:

import scalafx.application.JFXApp
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
object PieChartDemo extends JFXApp {
  val dataPairs = Seq(("Sun", 25), ("IBM", 17), ("HP", 25), ("Dell", 27), ("Apple", 5))
  stage = new JFXApp.PrimaryStage {
    title = "PieChartDemo"
    scene = new Scene {
      root = new PieChart() {
        title = "Pie Chart"
        clockwise = false
        data = ObservableBuffer(dataPairs.map {case (x, y) => PieChart.Data(x, y)})


There are a couple of new demos of charts available.

Easier way to create, add and remove event handlers and event filters

Focus here was on making it easier to create event handlers and event filters that deal with more than one event (Issue 77). That may be useful for instance in code that handles mouse interaction, especially when that interaction is context dependent. Here is a code snipped illustrating use of the new/improved `handleEvent` construct:

  val pane = new Pane() {...}
  // Define handling of mouse events and add it to the pane
  val subscription = pane.handleEvent(MouseEvent.Any) {
    me: MouseEvent => {
      me.eventType match {
        case MouseEvent.MousePressed => {...}
        case MouseEvent.MouseDragged => {...}
        case _ => {...}
  // Remove event handler when interaction is no longer needed

There are two new demos that illustrate this in more details: RectangleDrawingDemo and MultipleShapeDrawingDemo.

New implicit conversion for colors

You can now assign RGB color using tuples instead us using `Color.rgb(…)` methods, for instance:

import scalafx.Includes._
import scalafx.scene.shape.Rectangle
  val r = new Rectangle {
    // Instead of: fill = Color.rgb(64, 128, 196, 0.5)
    fill = (64, 128, 196, 0.5)
    // Instead of: stroke = Color.rgb(187, 56, 19)
    stroke = (187, 56, 26)
    // or using interpreting Int as hex values
    stroke = 0xBB381A

New demos

There are several new demo, most illustrate improvements to charts and event handling.

Improved demos

A few demos were improved. It is now also possible to easily run any demo from SBT, it used to default to ColorfulCircles demo.

  • MenuBarTest – improve layout – menu fill the top line, is not truncated on the right.
  • MenuTest – add examples of event handlers for menu items.
  • VideoCubesDemo – do not use hard coded locations to external files, use system property

Internal code cleanup and simplification

  • New `EventHandlerDelegate` trait to remove duplicate code for add/removeEventHandler/Filter in `Node`, `MenuItem`, `TableColumn`, `TreeItem`, and `Window`.
  • Provide explicit ScalaFX types in some additional cases when JavaFX types were inferred, to simplify API usage.
  • Improved handling of `null` assigned to a property – Some properties could be legally assigned `null` value. In this release more places are fixed where this used to lead to `NullPointerException`.

In SBT, fork tests so they are run on a separate JVM, but do not run individual tests is parallel

ScalaFX tests require initialization of JavaFX application thread. Running tests on a separate JVM avoids conflicts caused by JavaFX application thread initializations. It used to be that test can be run only once and SBT has to be restarted; now you can rerun tests without in the same SBT instance.

Build system and dependency upgrades

  • Use SBT 0.13
  • Scala 2.10.1 upgraded to 2.10.2
  • JUnit 4.10 to 4.11
  • Sbt-idea 1.3.0 to 1.5.1
  • Sbteclipse-plugin 2.1.1 to 2.2.0

Bug Fixes

  • Issue 61 – method ProgressBarTableCell#forTableColumn() did not work correctly.
  • Issue 66 – Wrapper classes should not be `final` – this prevents use of hierarchical builder pattern. Also update related VideoCubeDemo demo.
  • Issue 67 – MediaPlayer – simplify handling of Runnable. Do it without introducing overly generic implicit conversion of a code block to Runnable.
  • Issue 70 – could not compile code that used ‘EventHandler#handleEvent(…){…}'”.
  • TableColumn#removeEventHandler actually called delegated call to addEventHandler
  • Node#onTouchReleased and Scene#onTouchReleased actually delegated to onTouchPressed

Where to Get It

You can download ScalaFX binaries and source code from the project website.

Artifacts are also published on the Maven Central, so you can use them from you favorite build system SBT, Gradle, Maven, etc.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: