You css selector is wrong.
.scroll-pane:corner
selects Nodes with class "scroll-pane" which have a pseudo-class state "corner" activated. According to the css documentation, scroll pane has no "corner" pseudoclass.
.scroll-pane:corner > .viewport
would select a node with class "viewport" that had an (immediate) parent node with class "scroll-pane" and with that parent node having the pseudoclass state "corner" activated. So, if anything, you would be selecting the viewport here.
The css you need is
.scroll-pane > .corner {
-fx-background-color: #191A19 ;
}
Maybe have a look at a general purpose tutorial on css selectors, such as the one at w3schools
Update complete example:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class ScrollPaneStyledCorner extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setPrefHeight(200);
scrollPane.setPrefWidth(200);
TextArea textArea = new TextArea(System.getProperty("javafx.version"));
scrollPane.setContent(textArea);
scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
scrollPane.setHbarPolicy(ScrollBarPolicy.ALWAYS);
root.setCenter(scrollPane);
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("scrollPaneCorner.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
scrollPaneCorner.css:
.scroll-pane > .corner {
-fx-background-color: #191A19 ;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…