gpt4 book ai didi

javafx - 单击时更改 javafx 按钮颜色?

转载 作者:行者123 更新时间:2023-12-03 19:53:56 26 4
gpt4 key购买 nike

我知道我可以使用按下的伪选择器来设置颜色:

myButton:pressed{}

问题是,我试图通过执行以下操作来覆盖样式表中的 css 背景颜色,从而在代码中执行此操作:
myButton.setStyle("fx-background-color: #FFF");

后者失败确实改变了颜色。是不是一旦我设置了样式表就无法覆盖它?如何在单击时更改按钮颜色?

最佳答案

我不得不做类似的事情(这里是简化的,只有部分代码将样式更改为按钮),我这样做了,希望对您有所帮助

button.setOnAction((ActionEvent e) -> {
button.getStyleClass().removeAll("addBobOk, focus");
//In this way you're sure you have no styles applied to your object button
button.getStyleClass().add("addBobOk");
//then you specify the class you would give to the button
});

CSS:
.addBobOk{
-fx-background-color:#90EE90;
-fx-background-radius: 5,5,4;
-fx-background-insets: 0 0 -1 0,0,1;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
-fx-text-alignment: center;
}
.addBobOk:hover{

-fx-background-color:#64EE64;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
-fx-text-alignment: center;
}
.busy{

-fx-background-color:#B3B3B3;
-fx-text-alignment: center;
}
.busy:hover{

-fx-background-color:cdcbcb;
-fx-text-alignment: center;
}

关于javafx - 单击时更改 javafx 按钮颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com