Use Scala Swing with SBT to write GUI Program

Swing is a GUI widget toolkit for Java. It is part of Oracle’s Java Foundation Classes (JFC). Scala Swing is wrap most of the Java Swing’s API for Scala.

To use it in SBT, you need to add dependency:

name := "gui"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.11.7"
organization := "org.janzhou"

libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "1.0.2"

Here is a simple gui program you can try:

import scala.swing._

class UI extends MainFrame {
  title = "GUI Program #1"
  preferredSize = new Dimension(320, 240)
  contents = new Label("Here is the contents!")
}

object GuiProgramOne {
  def main(args: Array[String]) {
    val ui = new UI
    ui.visible = true
    println("End of main function")
  }
}

gui