java 使用 css 自定义 JavaFx Alert
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37354686/
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
Customize JavaFx Alert with css
提问by GOXR3PLUS
Searching in caspian.cssI found that I can customize dialog-pane.Alert extends Dialog so I tried some of of these lines of code:
在caspian.css 中搜索我发现我可以自定义 dialog-pane.Alert extends Dialog 所以我尝试了其中的一些代码行:
.dialog-pane {
-fx-background-color: black;
-fx-padding: 0;
.....
}
.dialog-pane > .expandable-content {
-fx-padding: 0.666em; /* 8px */
.....
}
.dialog-pane > .button-bar > .container {
-fx-padding: 0.833em; /* 10px */
.....
}
.....
but nothing changes.
但没有任何变化。
Question:How can I do that? I mean I want to customize the background, the buttons, the header and everything other.
问题:我该怎么做?我的意思是我想自定义背景、按钮、标题和其他所有内容。
回答by GOXR3PLUS
Take a look herehow to add stylesheetor|and styleclassto DialogPane,so you can add your costume css file.
看看这里如何添加样式表或|和的styleClass到DialogPane,这样你就可以添加你的服装css文件。
Example(picture + css code):
示例(图片 + css 代码):
.dialog-pane{
-fx-border-color:black;
-fx-border-width:2.0px;
}
/**Costumization of The Bar where the buttons are located**/
.dialog-pane > .button-bar > .container {
-fx-background-color:black;
}
.dialog-pane > .content.label {
-fx-padding: 0.5em 0.5em 0.5em 0.5em;
-fx-background-color: yellow;
-fx-text-fill:black;
-fx-font-size:15.0px;
}
/**Costumization of DialogPane Header**/
.dialog-pane:header .header-panel {
-fx-background-color: black;
}
.dialog-pane:header .header-panel .label{
-fx-background-color: yellow;
-fx-background-radius:10px;
-fx-text-fill:black;
-fx-font-size:15.0px;
}
/**Costumization of Buttons**/
.dialog-pane .button{
-fx-background-color:black;
-fx-text-fill:white;
-fx-wrap-text: true;
-fx-effect: dropshadow( three-pass-box, yellow, 10.0, 0.0, 0.0, 0.0);
-fx-cursor:hand;
}
.dialog-pane .button:hover{
-fx-background-color:white;
-fx-text-fill:black;
-fx-font-weight:bold;
}