java JavaFX 中的样式按下按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30273020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
style pressed button in JavaFX
提问by Elyas Hadizadeh
I've got a Button
in my FXML
file and i give a style to it by below CSS
Button
我的FXML
文件中有一个,我在下面给它一个样式CSS
.button {
-fx-background-color: linear-gradient(#ff5400, #be1d00);
-fx-background-radius: 30;
-fx-background-insets: 0;
-fx-text-fill: white;
}
as you can see the button has a new awesome style, but whenever i click on it, it remains as like as before and you can't understand is it clicked or not...
正如你所看到的按钮有一个新的很棒的样式,但是每当我点击它时,它仍然和以前一样,你无法理解它是否被点击......
As I searched, I found one solution in this link: Pressed CSS, but if you notice it is The CSS that is used by Web Browsers and JavaFX does not support it.
在我搜索时,我在此链接中找到了一个解决方案:Pressed CSS,但如果您注意到它是 Web 浏览器和 JavaFX 使用的 CSS 不支持它。
so what is the solution? I want my button changes its appearance when the users hit or click it.
那么解决方案是什么?我希望我的按钮在用户点击或点击时改变它的外观。
回答by ItachiUchiha
You need to add the psuedoclass state pressed
to you css and add new css to it, which will differentiate your current button css with that when pressed :
您需要将 psuedoclass 状态添加pressed
到您的 css 并向其添加新的 css,这将在按下时区分您当前的按钮 css:
.button:pressed {
// Your new css
}
For changing the style while hovering the button
use :
用于在hovering the button
使用时更改样式:
.button:hover {
// Your new css
}
For better understanding of what style you can add for styling the button, you can go through How to make a button appear to have been clicked or selected?
为了更好地了解可以为按钮样式添加什么样式,您可以查看如何使按钮看起来已被单击或选中?
回答by dizad87
for arrayLists on javaFX, try this on the CSS to change colors on mouse click:
对于 javaFX 上的 arrayLists,请在 CSS 上尝试此操作以在鼠标单击时更改颜色:
.list-cell:selected { -fx-background-color: yellow; }
.list-cell:selected { -fx-background-color: 黄色; }