无法将 CSS 类 添加到我的 JavaFX 标签

Cannot add CSS classes to my JavaFX Label

我正在制作一个简单的待办事项应用程序。这是它的简化版本:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        ListView<Label> todoListView = new ListView();

        Label doneTodo = new Label ("This todo is meant to be finished and struck through");
        doneTodo.getStyleClass().add("done"); // Add the "done" class to this to-do
        Label undoneTodo = new Label("This todo is meant to be undone and therefore isn't struck through");

        // Add both to-dos to the listview
        addTodo(doneTodo, todoListView);
        addTodo(undoneTodo, todoListView);

        // Set the listview as the scene, and add the stylesheet
        Scene scene = new Scene(todoListView, 600, 550);
        scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());

        primaryStage.setTitle("Label not taking on Strikethrough");
        primaryStage.setScene(scene);
        primaryStage.show();


    }

    // Adds the to-do (in this case just a simple Label) to the listview
    private static void addTodo(Label todo, ListView<Label> todoList) {
        todoList.getItems().add(todo);
    }


    public static void main(String[] args) {
        launch(args);
    }
}

这是我的 CSS class:

.done {
    -fx-strikethrough: true;
}

当我 运行 代码时,-fx-strikethrough 属性 没有显示在我的标签上。请注意,尽管这是我的应用程序的简化版本,但问题仍然存在:JavaFX 标签内的文本未被删除。

再次,对于我的问题中的任何不足之处,我们深表歉意。我是 Stack Overflow 的新手!

提前致谢。

CSS 规则应应用于标签节点下的文本节点:

.done .text {
    -fx-strikethrough: true;
}