JavaFX ScrollPane 如何设置透明背景

gro*_*und 3 css java javafx scenebuilder

我无法在scrollpane. 可能是因为它包含anchorpane, 并且anchorpane包含按钮?白色背景来自scrollpane和红色来自anchorpane

在此处输入图片说明

GOX*_*LUS 6

你必须使用css并且像这样:


.scroll-pane{
   -fx-background-color:transparent;
}
Run Code Online (Sandbox Code Playgroud)

和(因为ScrollPane有一个Viewport

.scroll-pane > .viewport {  //not .scrollpane but .scroll-pane
   -fx-background-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)

或者

.scroll-pane .viewport {
       -fx-background-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)

如果它不起作用,要么你没有很好地定义外部 css 文件,要么你在 ScrollPane 中添加了某种容器,它也有一个默认的背景颜色。


Rah*_*ngh 0

在 fxml 中为 AnchorPane 设置一个 id,然后在 css 中将 id 分配给 -fx-background-color :透明。

希望这有效。

如果没有请参考这个问题

JavaFX ScrollPane 边框和背景