我不能改变JavaFX中ScrollPane的边角颜色

我不能改变JavaFX中ScrollPane的边角颜色

本文介绍了我不能改变JavaFX中ScrollPane的边角颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的css代码看起来像这样,但它仍然不工作。 scrollpane?

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

推荐答案

的任何其他方面。您的CSS选择器是错误的。

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

将选择一个具有类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.

您需要的css是

.scroll-pane > .corner {
    -fx-background-color: #191A19 ;
}

也许看看一个关于css选择器的通用教程,例如一个在

Maybe have a look at a general purpose tutorial on css selectors, such as the one at w3schools

更新完整示例:

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:

scrollPaneCorner.css:

.scroll-pane > .corner {
    -fx-background-color: #191A19 ;
}

这篇关于我不能改变JavaFX中ScrollPane的边角颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:31