【问题标题】:Changing Id of nodes in different controllers更改不同控制器中节点的 ID
【发布时间】:2015-02-21 15:06:55
【问题描述】:

我在应用程序类中有这段代码

scene.getStylesheets().add(getClass().getResource(CONSTANTS.DESIGN_CSS.directory).toExternalForm());

还有这个 CSS 文件

@CHARSET "UTF-8";

#mainList .list-cell {
    -fx-background-color: null;
    -fx-font-size: 24px;
    -fx-text-fill: linear-gradient( from 0.0% 0.0% to 0.0% 50.0%, reflect, rgba(255,0,0,0.28) 0.0, rgba(102,243,255,0.58) 50.0, rgba(179,179,179,0.45) 70.0, rgba(179,179,179,0.45) 100.0);
}
#mainList .list-cell:hover {
    -fx-text-fill:linear-gradient( from 0.0% 0.0% to 100.0% 100.0%, reflect, rgb(255,255,255) 0.0, rgb(255,255,77) 100.0);
}

#stoperButton .button { 
    -fx-background-color:  linear-gradient( from 50.0% 100.0% to 100.0% 100.0%, rgb(0,0,0) 0.0, rgb(255,255,255) 100.0);
}

#stoperButton .button:hover {
    -fx-background-color: #9ACD32;
}

在第一个加载的控制器中,我可以轻松做到这一点,并且它可以工作:

listView.setId("mainList");

但这(在不同的控制器中)没有错误但没有效果:

buttSTOP.setId("stoperButton");

和改变场景的根有关系吗?

【问题讨论】:

    标签: css javafx-8


    【解决方案1】:

    选择器

    #stoperButton .button { ... }
    

    匹配具有样式类“button”并且是具有css id“stoperButton”的节点的后代的节点。

    我认为你想要的只是

    #stoperButton {
        -fx-background-color:  linear-gradient( from 50.0% 100.0% to 100.0% 100.0%, rgb(0,0,0) 0.0, rgb(255,255,255) 100.0);
    }
    
    #stoperButton:hover {
        -fx-background-color: #9ACD32;
    }
    

    【讨论】:

    • 是的,它有效。我只是不明白为什么它与#mainList .list-cell:hover{... 不同的类比??
    • stoperButton 中没有按钮,因此#stoperButton .button 不匹配任何内容。另一方面,ListViews 包含ListCells,所以#mainList .list-cell 匹配mainList 中的所有列表单元格(即您将样式应用于各个列表单元格)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 2011-12-23
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多