简体   繁体   English

javafx2.2制作一个透明背景的滚动条

[英]javafx2.2 making a scrollbar with transparent background

I am trying to make a scrollpane with a scrollbar that has transparent (or at least solid) background by styling it with css in javafx 2.2.3. 我试图通过在javafx 2.2.3中使用css设置样式来创建具有透明(或至少是实心)背景的滚动条的滚动窗格。

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

Strangely, the code above makes scrollbar black. 奇怪的是,上面的代码使滚动条变黑。 Giving -fx-base any value with alfa does that. 使用alfa给予-fx-base任何值都可以。

Background-color has no efect at all... 背景色完全没有效果......

What am I missing? 我错过了什么?

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: 与示例中的滚动条相关的css是:

.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 . 我通过研究默认JavaFX 2.2 css样式表caspian.css的滚动条部分来确定要使用的css。

Output of the sample is: 样本的输出是:

葛底斯堡地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM