简体   繁体   English

我无法在JavaFX中更改ScrollPane的角色

[英]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. 我的css代码看起来像这样但它仍然不起作用。 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 我的语法有问题,还是整个视图端口问题不允许我编辑的任何其他方面

You css selector is wrong. 你的css选择器是错的。

.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. 根据css文档 ,滚动窗格没有“角落”伪类。

.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. 将选择具有类“viewport”的节点,该节点具有带有“scroll-pane”类的(立即)父节点,并且该父节点具有激活的伪类状态“corner”。 So, if anything, you would be selecting the viewport here. 所以,如果有的话,你会在这里选择视口。

The css you need is 你需要的CSS是

.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 也许看一下关于css选择器的通用教程,比如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: scrollPaneCorner.css:

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

在此输入图像描述

It works : 有用 :

.corner {    
    -fx-background-color: #363636 ;
}

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

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