无法使用TornadoFX将节点置于StackPane中

我试图做一个简单的视图,我有一个背景节点( 现在,我有一个文本节点在这里,但最后的节点将是一个SVG路径 )在VBox后面。 我试图让我的背景节点居中在根StackPane之前我移动到实施VBox ,但我似乎无法让我的节点正确居中。

这是我的课程:

 class UserInputUI : App(InputView::class, UIStyles::class) { init { reloadStylesheetsOnFocus() } override fun start(stage: Stage) { stage.minWidth = 1024.0 stage.minHeight = 768.0 super.start(stage) } } class InputView : View() { override val root = StackPane() init { text("I wish to be centered") { stackpaneConstraints { alignment = Pos.CENTER addClass(UIStyles.headerFontStyle) } } } } 

和我的UIStyles类..如果是相关的。

 class UIStyles : Stylesheet() { companion object { val headerFontStyle by cssclass() private val headerFontColor = Color.BLACK } init { headerFontStyle { fontSize = 48.px } } } 

有没有一种不同的方式,我应该在StackPane的中间居中节点? 我已经在InputView初始化函数中尝试过root.alignment = Pos.CENTER ,但无济于事。

帮助这个可怜的盒子

我觉得我正在做一些愚蠢的事情。任何帮助? 谢谢!

尝试在minWidth/Height设置调用之前放置super.start()调用。

我们已经在Slack上讨论过了,我们相信Linux和Mac / Windows之间可能存在JavaFX的差异,因为你的代码在Mac / Windows上开箱即用,但在Linux上却失败了。

当您在minWidth/minHeight配置之前放置super.start()调用时,场景已经为您创建,所以我相信这是原因。

一个StackPane默认将它的子stackpaneConstraints ,所以不需要stackpaneConstraints配置。 如果您使用构建器来定义堆栈窗格,您的代码也将看起来更清晰:

 class InputView : View() { override val root = stackpane { text("I wish to be centered") } }