Hierarchical Syntax

A programmer-friendly, hierarchical syntax for building up the scene graph.

Natural Bind Expressions

Rich operator support makes binding expressions read like ordinary code.

Fully Type-Safe APIs

The Scala compiler checks and infers types across the full API surface.

Seamless Interoperability

Mix ScalaFX and plain JavaFX controls freely in the same codebase.

ScalaFX in a Few Lines

import scalafx.application.JFXApp3
import scalafx.geometry.Insets
import scalafx.scene.Scene
import scalafx.scene.control.{Button, Label, Slider, TextField}
import scalafx.scene.layout.VBox
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle

object BindingDemo extends JFXApp3:

  override def start(): Unit =
    val nameField = new TextField:
      promptText = "Your name"

    val greeting = new Label:
      text <== nameField.text.map(name => s"Hello, $name!")

    val slider = new Slider(0, 100, 10)

    val bar = new Rectangle:
      height = 20
      fill = Color.SteelBlue
      width <== slider.value * 2.5

    val okButton = new Button("OK"):
      disable <== nameField.text.isEmpty

    stage = new JFXApp3.PrimaryStage:
      title = "Binding demo"
      scene = new Scene:
        root = new VBox:
          spacing = 10
          padding = Insets(20)
          children = Seq(nameField, greeting, slider, bar, okButton)

04-binding-demo.png

Four ideas, one small program:

This is the whole program — no boilerplate trimmed. See it explained line by line in Properties and Bindings, or start from the beginning with For the Impatient.