JavaFX ScrollPane 如何设置透明背景

问题描述 投票:0回答:3

我无法在

scrollpane
中设置透明背景。可能是因为它包含
anchorpane
,并且
anchorpane
包含按钮?白色背景来自
scrollpane
,红色来自
anchorpane

enter image description here

java css javafx scenebuilder
3个回答
8
投票

你必须使用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中添加了某种容器,它也有默认的背景颜色。


0
投票

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

希望这有效。

如果没有请参考这个问题

JavaFX ScrollPane 边框和背景


0
投票

在这里您可以找到有关如何在 fxml 中正确执行此操作的详细说明。

style =“-fx-background:透明;-fx-background-color:透明;”

© www.soinside.com 2019 - 2024. All rights reserved.