Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 25, 2024 08:39
Show Gist options
  • Save dacr/bf64e466de47ae5411e23d576d3b51ec to your computer and use it in GitHub Desktop.
Save dacr/bf64e466de47ae5411e23d576d3b51ec to your computer and use it in GitHub Desktop.
scalafx hello world with reflection example / published by https://github.com/dacr/code-examples-manager #ffda5b05-7733-415b-a7d2-640ea46629ae/9f8c0325579d9afe784c4969f7d5219183c10f9d
// summary : scalafx hello world with reflection example
// keywords : scala, user-interface, javafx, scalafx, helloworld
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : ffda5b05-7733-415b-a7d2-640ea46629ae
// created-on : 2024-01-07T16:13:37+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
// To setup the right jdk with javafx enabled :
// nix-shell nix-shell-scalafx.nix (https://gist.github.com/dacr/f64acff9d7e128183f721038e7e0a94d)
// ---------------------
//> using scala "3.4.2"
//> using dep "org.scalafx::scalafx:21.0.0-R32"
// ---------------------
// coming from
// https://github.com/scalafx/scalafx/blob/master/scalafx-demos/src/main/scala/scalafx/HelloScalaFX.scala
import scalafx.application.JFXApp3
import scalafx.application.JFXApp3.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.effect._
import scalafx.scene.layout.HBox
import scalafx.scene.paint.Color._
import scalafx.scene.paint.{LinearGradient, Stops}
import scalafx.scene.text.Text
object HelloScalaFX extends JFXApp3 {
override def start(): Unit = {
stage = new PrimaryStage {
title = "ScalaFX Hello World"
width = 650
height = 450
scene = new Scene {
fill = Black
content = new HBox {
children = Seq(
new Text {
text = "Scala"
style = "-fx-font-size: 100pt"
fill = new LinearGradient(endX = 0, stops = Stops(PaleGreen, SeaGreen))
},
new Text {
text = "FX"
style = "-fx-font-size: 100pt"
fill = new LinearGradient(endX = 0, stops = Stops(Cyan, DodgerBlue))
effect = new DropShadow {
color = DodgerBlue
radius = 25
spread = 0.25d
}
}
)
effect = new Reflection {
fraction = 0.5d
topOffset = -5.0d
bottomOpacity = 0.75d
input = new Lighting { light = new Light.Distant { elevation = 60 } }
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment