我正在尝试获取它,以便以模态方式打开的片段具有半透明背景。我可以通过设置舞台的不透明度来做到这一点,但是我实际上不能使用该方法,因为它会使模态窗口中的所有文本和按钮也变成半不透明的。有没有办法将舞台的背景设置为透明?或将其设置为具有较低alpha值的颜色,然后使片段的根透明?这是我进行测试以显示问题的测试。
import javafx.geometry.Pos
import javafx.scene.paint.Color
import javafx.stage.StageStyle
import tornadofx.*
fun main(args: Array<String>) {
launch<ModalTransparencyTest>(args)
}
class ModalTransparencyTest: App(TestView::class)
class TestView : View() {
override val root = vbox {
alignment = Pos.CENTER
button("open modal window").action {
val newStage = TestFragment().openModal(StageStyle.UTILITY, escapeClosesWindow = true)
if (newStage != null) {
newStage.scene.fill = Color.TRANSPARENT
//don't want to set stage's opacity as that will set
//all of the stage's children to be less opqaue as well
//just want to set the stage's background to be semi-transparent
}
}
}
override fun onDock() {
super.onDock()
primaryStage.width = 800.0
primaryStage.height = 600.0
}
}
class TestFragment: Fragment() {
override val root = vbox {
text("I am a test fragment")
style {
backgroundColor += c(.2, .2, .2, .8)
}
prefWidth = 300.0
prefHeight = 200.0
}
}
如您所见,片段的背景并没有像预期的那样透明。我做错了吗?任何帮助将不胜感激!