简体   繁体   English

JavaFX ScrollPane如何设置透明背景

[英]JavaFX ScrollPane how set transparent background

I can not set transparent background in scrollpane . 我无法在scrollpane设置透明背景。 Probably because it contains anchorpane , and that anchorpane contains buttons? 可能是因为它包含anchorpane ,并且该anchorpane包含按钮? White background from scrollpane and red from anchorpane : scrollpane白色背景和anchorpane scrollpane红色:

在此处输入图片说明

Set an id to your AnchorPane in the fxml and then in your css assign the id to -fx-background-color : transparent. 在fxml中为您的AnchorPane设置一个ID,然后在您的CSS中将ID分配给-fx-background-color:transparent。

Hope this works. 希望这行得通。

if not Please Refer to this question 如果不是,请参阅此问题

JavaFX ScrollPane border and background JavaFX ScrollPane边框和背景

You have to use css and like this: 您必须使用css并像这样:


.scroll-pane{
   -fx-background-color:transparent;
}

and(cause ScrollPane has a Viewport ) 并且(因为ScrollPane具有Viewport

.scroll-pane > .viewport {  //not .scrollpane but .scroll-pane
   -fx-background-color: transparent;
}

or 要么

.scroll-pane .viewport {
       -fx-background-color: transparent;
}

If it doesn't work,either you have not defined externall css file well,or you have added some kind of container into the ScrollPane which has also a default background color. 如果它不起作用,则说明您没有很好地定义外部CSS文件,或者您已在ScrollPane中添加了某种容器,该容器也具有默认的背景色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM