Asp*_*ger 0 javafx javafx-2 javafx-8
我知道我可以使用按下的伪选择器设置颜色:
myButton:pressed{}
Run Code Online (Sandbox Code Playgroud)
问题是,我试图通过执行以下操作来覆盖样式表中的css背景颜色,从而在代码中执行此操作:
myButton.setStyle("fx-background-color: #FFF");
Run Code Online (Sandbox Code Playgroud)
后者失败确实改变了颜色.可能是因为一旦我设置我的样式表,我不能覆盖它?如何在点击时更改按钮颜色?
我不得不做类似的事情(这里简化了,只有代码的一部分改变了按钮的样式)我做了这个,我希望它对你有所帮助
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
});
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22834 次 |
| 最近记录: |