FXML样式不适用于动态添加TreeView TreeItem

时间:2014-11-12 15:51:24

标签: css javafx fxml

我正在尝试将css样式应用于A TreeView TreeItem,但出于某种原因,该项目并未启动并应用该样式。这是fxml文件的片段。正如您所看到的,TreeView没有任何项目,这是因为我稍后会添加它们。

<AnchorPane styleClass="/media/css/TreeItem.css" id="AnchorPane" fx:id="main" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="db.manager.MainController">
    <children>
        <AnchorPane>
            <children>
                <TreeView editable="true" showRoot="false" />
            </children>
        </AnchorPane>
    </children>
</AnchorPane>

然后我在上面fxml中提到的文件css文件中有以下css:

.tree-cell{
    -fx-indent: 100;
    -fx-underline: true;
    -fx-background-image: url("/media/images/database.png");
    -fx-background-repeat: no-repeat;
}

我没有收到任何错误,所以我知道该文件正在加载,但样式并未应用于新添加的TreeItem,我不知道为什么。

1 个答案:

答案 0 :(得分:1)

你需要

<AnchorPane stylesheets="/media/css/TreeItem.css" ... >

<AnchorPane styleClass="/media/css/TreeItem.css" ... >
相关问题