这是我的Scrollpane的fxml,它位于GridPane
中 <ScrollPane fx:id="scrollPane" prefHeight="200.0" prefWidth="200.0" style=".scroll-pane .track{-fx-opacity: 0;} .scroll-pane .scroll-bar{-fx-base: transparent;}" vbarPolicy="AS_NEEDED" styleClass="myscrollpane" GridPane.columnIndex="0" GridPane.rowIndex="1">
<content>
</content>
<GridPane.margin>
<Insets top="10.0" />
</GridPane.margin>
</ScrollPane>
我想申请的CSS是
.myscrollpane .scroll-bar:horizontal ,
.myscrollpane .scroll-bar:vertical{
-fx-background-color:#d7dddd;
}
.myscrollpane .increment-button ,
.myscrollpane .decrement-button {
-fx-background-color:transparent;
-fx-background-radius: 0em;
-fx-padding:0 0.5 0 0;
}
.mylistview .scroll-bar .increment-arrow,
.mylistview .scroll-bar .decrement-arrow {
-fx-shape: " ";
-fx-padding:0;
}
.myscrollpane .scroll-bar:horizontal .track ,
.myscrollpane .scroll-bar:vertical .track{
-fx-background-color: transparent;
-fx-border-color:derive(gray,80%);
-fx-background-radius: 0em;
}
.myscrollpane .scroll-bar:horizontal .thumb,
.myscrollpane .scroll-bar:vertical .thumb {
-fx-background-color : #989898;
-fx-background-insets: 1, 0, 0;
-fx-background-radius: 0em;
}
.myscrollpane .scroll-bar:horizontal:hover .track ,
.myscrollpane .scroll-bar:horizontal:pressed .track ,
.myscrollpane .scroll-bar:vertical:hover .track,
.myscrollpane .scroll-bar:vertical:pressed .track{
-fx-background-color: derive(#434343,20%);
-fx-opacity: 0.2;
-fx-background-radius: 0em;
}
.myscrollpane .scroll-bar .thumb:hover,
.myscrollpane .scroll-bar .thumb:pressed{
-fx-background-color: derive(black,50%);
}
使用myscrllpane是Scroll-pane的类。 但它没有任何意义。即直接在fxml中编写css或使用url嵌入CSS。因为我必须要求将其应用于滚动窗格的滚动条。