When I upgraded by JavaFX app from JavaFX 2 to JavaFX 8, I noticed that ScrollPanes always showed up as gray rectangles, even with a background color set or the background set to be transparent.
I found the solution in this discussion: https://community.oracle.com/thread/3538169
First I needed this:
.scroll-pane > .viewport {
-fx-background-color: transparent;
}
Then I could set the background color to whatever I like. In this case, I'm making all ScrollPane backgrounds transparent:
.scroll-pane {
-fx-background-color: transparent;
}
Came acroos this just now, it's not working with -fx-background-color, but it is with -fx-background
.scroll-pane {
-fx-background: #FFFFFF;
-fx-border-color: #FFFFFF;
}
In-source approach:
Once it's added to the scene/stage, you can trigger off the width or height property to get access to the viewport styling.
ScrollPane myPane = new ScrollPane();
myPane.widthProperty().addListener((o) -> {
Node vp = logMessagePane.lookup(".viewport");
vp.setStyle("-fx-background-color:#434547;");
});
来源:https://stackoverflow.com/questions/22952531/scrollpanes-in-javafx-8-always-have-gray-background