I'm using JavaFX in Eclipse from JDK 1.8.0_72. I want to display an image in the background of a scroll pane. I'm using the following code to do this:
ScrollPane s2 = new ScrollPane();
s2.setContent(label);
s2.setStyle("-fx-background-image: url('DungeonRoomImage.png');");
This works just fine on other objects such as Labels and GridPanes but for some reason not on scroll panes where it's displaying a grey block in the middle covering up the image. If you look closely between the border and grey center you can see the image peeking out.
https://gyazo.com/597ce351f158c1d66c33fe301bd75feb
The same issue occurs when changing the background color of a scroll pane, but is solved by using
-fx-background:
instead of:
-fx-background-color:
I've tried using setBackground but that renders the same result
s2.setBackground(new Background(new BackgroundImage(new Image("DungeonRoomImage.png"), null, null, null, null)));
Could anyone suggest a way to get rid of the grey background or a way to work around the issue? Here's how the background image should look
Set the background image on the scroll pane's viewport. Using an external CSS file:
.scroll-pane .viewport {
-fx-background-image: url('DungeonRoomImage.png');
}