I use the Border Pane as a layout. The bottom child has a ScrollPane, which should use the complete width (stretch) of the Border Pane - regardless of its content.
val scrollPane = new ScrollPane() {
hbarPolicy = ScrollBarPolicy.ALWAYS
content = new TextFlow() {
children.add(new Text("Hello World"))
}
}
stage = new PrimaryStage {
title = "ScalaFX Hello World"
width = 1024
height = 768
scene = new Scene {
content = new BorderPane() {
center = Label("This is my center text")
bottom = new Pane {
children.add(scrollPane)
}
}
}
It looks during runtime the following way:
Any chance I can achieve this without manually setting the width of the ScrollPane ?
In ScalaFX, unless a parent is passed, Scene is instantiated with an empty Group.
class Scene(override val delegate: jfxs.Scene = new jfxs.Scene(new jfxs.Group()))
So, instead of setting content
, set the root
of the Scene.
scene = new Scene {
root = new BorderPane() {
center = Label("This is my center text")
bottom = scrollPane
}
}
You must have noticed that I even removed the new Pane that you were adding to bottom before adding the ScrollPane.
MCVE
import scalafx.application.JFXApp
import scalafx.scene.Scene
import scalafx.scene.control.ScrollPane.ScrollBarPolicy
import scalafx.scene.control.{Label, ScrollPane}
import scalafx.scene.layout.BorderPane
import scalafx.scene.text.{Text, TextFlow}
object Main extends JFXApp {
val scrollPane = new ScrollPane() {
hbarPolicy = ScrollBarPolicy.ALWAYS
content = new TextFlow() {
children.add(new Text("Hello World"))
}
}
stage = new JFXApp.PrimaryStage {
title.value = "Hello Stage"
width = 200
height = 150
scene = new Scene {
root = new BorderPane() {
center = Label("This is my center text")
bottom = scrollPane
}
}
}
}
Screenshot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.