java JavaFX 隐藏 ScrollPane 灰色边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12899788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:42:14  来源:igfitidea点击:

JavaFX Hide ScrollPane gray border

javajavafx-2javafx

提问by nailujed

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

有没有办法在 JavaFX 中隐藏 ScrollPane 控件的灰色边框?

回答by Sergey Grinev

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

JavaFX 中的所有控件都可以使用 CSS 样式进行修改。您可能需要查看参考教程

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:

Gray ScrollPane 的边框实际上是在内容后面可见的唯一背景部分。所以你可以通过修改背景来改变它:

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

回答by Andreas

Or in CSS

或者在 CSS 中

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

回答by 22samuelk

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

在纯Java中,没有CSS,你需要像这样设置背景,这比CSS的方法要冗长得多。

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

回答by nickthecoder

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

使边框透明将在边缘周围留下 1 像素的间隙。恕我直言,正确答案是 Jens Piegsa 链接到的答案。 https://stackoverflow.com/a/17540428/1725096