ScrollPanes in JavaFX 8 always have gray background

谁都会走 提交于 2019-11-29 05:25:05

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;");
    });
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!