44

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.

4 Answers 4

93

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;
}
2
  • 1
    See here for other JavaFX 2 to JavaFX 8 issues.
    – Jurgen
    Apr 16, 2014 at 15:18
  • Setting the color in your first snippet above worked for me-didn't need the second
    – torwalker
    Dec 22, 2015 at 12:49
27

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;
}
1
  • 3
    This should be accepted as the answer, as the current accepted answer is more of a hack-around Dec 18, 2019 at 14:48
5

To alter borders, you would have to use "fx-background-color" . To modify the viewport's background color, you should modify the "fx-background" attribute.

I used white for both colors :

scrollPane.setStyle("-fx-background: rgb(255,255,255);\n -fx-background-color: rgb(255,255,255)");

0

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;");
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.