如何制作按钮:悬停会影响java fx中的lebel

问题描述 投票:1回答:1

我正在尝试使用Java fx中的css制作一个标签和一个按钮连接,但是不起作用。

#B0{
    -fx-border-radius:10px;
    -fx-background-color: blue;
}
#B0:hover{

    -fx-border-radius:10px;
    -fx-transition: 1s ease-in-out;
    -fx-background-color: green;

}
#B0:hover ~ #label{

    -fx-background-color: green;

}

标签未更改背景颜色

css javafx
1个回答
0
投票

javafx中可用的选择器受到限制。兄弟选择器未实现。实现这样的唯一方法是修改标签或公共父对象,以允许使用JavaFX在Java代码中实现的选择器:

PseudoClass containsButtonHover = PseudoClass.getPseudoClass("contains-button-hover");
Button button = ...

// apply pseudoclass to common parent iff button is hovered
button.hoverProperty().addListener((o, oldValue, newValue) -> button.getParent().pseudoClassStateChanged(containsButtonHover, newValue));
#B0{
    -fx-border-radius:10px;
    -fx-background-color: blue;
}
#B0:hover{

    -fx-border-radius:10px;
    -fx-transition: 1s ease-in-out;
    -fx-background-color: green;

}
*:contains-button-hover>#label {
    -fx-background-color: green;
}
© www.soinside.com 2019 - 2024. All rights reserved.