css - 更改不同 Controller 中节点的 Id

标签 css javafx-8

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

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;
}

在加载的第一个 Controller 中我可以很容易地做到这一点并且它有效:

listView.setId("mainList");

但这(在不同的 Controller 中)让我没有错误但没有效果:

buttSTOP.setId("stoperButton");

跟改变场景根有关系吗?

最佳答案

选择器

#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;
}

关于css - 更改不同 Controller 中节点的 Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28647266/

相关文章:

javascript - 下拉列表在不需要的时间关闭

jquery - 使用 960grid 在 grid_12 类中内联显示 div 元素

html - 如何将段落设置到图像底部?

javascript - 如何使用 CSS 和 JS 一次为多个模态添加进出过渡效果?

javascript - 我怎样才能隐藏卡片?

Java 循环对象

java - 在 updateProgress 期间将文本附加到 JavaFX TextArea

java - 无法从静态上下文中引用非静态方法 getHostServices()

JavaFx:标签文本宽度

java - Pane 形状修改