Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

java - I can not change the corner color of a ScrollPane in JavaFX

My css code for it looks like this yet it still doesn't work. scrollpane?

.scroll-pane:corner > .viewport {

-fx-background-color : #191A19;

}

Is there a problem with my syntax or does the whole view port issue not allow me to edit any other aspect of the

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ;
}

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...