我无法在 scrollpane
中设置透明背景。可能是因为它包含 anchorpane
,而那个 anchorpane
包含按钮? scrollpane
的白色背景和 anchorpane
的红色背景:
最佳答案
你必须使用 css 并且像这样:
.scroll-pane{
-fx-background-color:transparent;
}
并且(因为 ScrollPane
有一个 Viewport
)
.scroll-pane > .viewport { //not .scrollpane but .scroll-pane
-fx-background-color: transparent;
}
或
.scroll-pane .viewport {
-fx-background-color: transparent;
}
如果它不起作用,要么您没有很好地定义外部 css 文件,要么您在 ScrollPane 中添加了某种容器,该容器也具有默认背景色。
关于JavaFX ScrollPane如何设置透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40253661/