nailujed
nailujed

Reputation: 1179

JavaFX Hide ScrollPane gray border

Is there any way of hiding the gray border of an ScrollPane control in JavaFX ?

Upvotes: 30

Views: 20109

Answers (5)

Aetherial
Aetherial

Reputation: 81

If you really want to blow away any pre-defined styles applied you can use:

ScrollPane scrollPane = new ScrollPane();    
scrollPane.getStyleClass().clear();

This also works for any sub-type of Node

Upvotes: 1

nickthecoder
nickthecoder

Reputation: 131

Making the border transparent will leave a 1 pixel gap around the edge. IMHO, the correct answer is the one that Jens Piegsa linked to. https://stackoverflow.com/a/17540428/1725096

Upvotes: 6

sk22
sk22

Reputation: 867

In pure Java, without CSS, you need to set the background like this, which is a lot more verbose than the CSS approach.

ScrollPane scrollPane = new ScrollPane();
scrollPane.setBackground(
  new Background(new BackgroundFill(Color.TRANSPARENT, null, null))
);

Upvotes: 5

Andreas
Andreas

Reputation: 347

Or in CSS

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

Upvotes: 12

Sergey Grinev
Sergey Grinev

Reputation: 34498

All controls in JavaFX can be modified using CSS styling. You may want to take a look at reference or tutorial.

Gray ScrollPane's border is actually the only part of the background which is visible behind the content. So you can change it by modifying the background:

    ScrollPane sp = new ScrollPane();
    sp.setStyle("-fx-background-color:transparent;");

Upvotes: 48

Related Questions