8

我正在尝试通过在 javafx 2.2.3 中使用 css 对其进行样式设置来制作具有透明(或至少纯色)背景的滚动条的滚动窗格。

.scroll-pane .track{-fx-opacity: 0;}
.scroll-pane .scroll-bar{-fx-base: transparent;}

奇怪的是,上面的代码使滚动条变黑了。用 alfa 给 -fx-base 任何值就可以了。

背景颜色根本没有效果......

我错过了什么?

4

1 回答 1

10

Here is a sample which displays a scroll bar with a transparent background.

The sample includes some extra program logic to only show visual feedback on the scrollbar when the user hovers over the scrollbar - you may or may not need that.

The css related to the scrollbar in the sample is:

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

.address .scroll-bar .increment-button {
  visibility: hidden;
}

.address .scroll-bar .decrement-button {
  visibility: hidden;
}

.address .scroll-bar:vertical {
  -fx-background-color: transparent;
}

.address .scroll-bar:vertical .track-background {
  visibility: hidden;
}

.address .scroll-bar:vertical .track {
  visibility: hidden;
}

.address .hide-thumb .scroll-bar:vertical .thumb {
  -fx-background-color: transparent;
}

Where the scroll bar being made transparent has the additional custom style class of address assigned to it.

I determined the css to use by studying the scroll-bar section of the default JavaFX 2.2 css stylesheet caspian.css.

Output of the sample is:

The Gettysburg address

于 2012-11-02T20:43:57.277 回答