JavaFX ScrollPane border and background

こ雲淡風輕ζ 提交于 2019-11-27 13:57:40

问题


I'm having some problem regarding the default background and border of the ScrollPane. Using this style made the problem clearer to see.

setStyle("-fx-background-color:blue; -fx-border-color:crimson;");

I've tried this style and got no luck only the red border gone and left me with the blue one.

setStyle("-fx-background-color:blue; -fx-background-insets:0; -fx-border-color:crimson; -fx-border-width:0; -fx-border-insets:0;");

I've looked at this old post JavaFX Hide ScrollPane gray border and http://docs.oracle.com/javafx/2/ui_controls/editor.htm

This line of code doesn't work neither

scrollPane.getStyleClass().add("noborder-scroll-pane");

Thanks


回答1:


In the current version of JavaFX 8, you can use the edge-to-edge style class to remove the border entirely:

<ScrollPane styleClass="edge-to-edge"/>



回答2:


I have found a solution and would liked to post it here so others won't need to waste their time find it again.

By looking at the default css of JavaFx (caspian.css) which has been extracted from the library using this command.

jar xf jfxrt.jar com/sun/javafx/scene/control/skin/caspian/caspian.css

I could see that the one I missed is

-fx-padding: 0;

So this is the css class I'm using.

.scroll-pane {
    -fx-background-insets: 0;
    -fx-padding: 0;
}

.scroll-pane:focused {
    -fx-background-insets: 0;
}

.scroll-pane .corner {
    -fx-background-insets: 0;
}



回答3:


Try use this first

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

Before setting the background color




回答4:


There seems to be a simple solution, which is to use "-fx-background: rgb(80,80,80);", that is,

scrollPane.setStyle("-fx-background: rgb(80,80,80);");

At least this works perfectly for me, while "-fx-background-color: rgb(80,80,80);" or "-fx-control-inner-background: rgb(80,80,80);" do not work in javafx 8. "-fx-background-color: rgb(80,80,80);" did work in earlier versions of javafx.




回答5:


You can use:

-fx-background-color: transparent;
-fx-control-inner-background: transparent;

If you set only -fx-background-color, you will see the color change is applied to only the ScrollPane's inner edges, and the color of the center area is still not changed.

The -fx-control-inner-background property will change the color of that center area.



来源:https://stackoverflow.com/questions/17540137/javafx-scrollpane-border-and-background

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