我无法在
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中添加了某种容器,它也有默认的背景颜色。
在 fxml 中为 AnchorPane 设置一个 id,然后在 css 中将 id 分配给 -fx-background-color :透明。
希望这有效。
如果没有请参考这个问题
在这里您可以找到有关如何在 fxml 中正确执行此操作的详细说明。!
style =“-fx-background:透明;-fx-background-color:透明;”