使用css自定义JavaFx警报 [英] Customize JavaFx Alert with css

查看:624
本文介绍了使用css自定义JavaFx警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

caspian.css 中搜索我发现我可以自定义对话框窗格.Alert扩展了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 * /
.....
}

.....

但没有任何变化。



问题:
我该怎么做?我的意思是我想自定义背景,按钮,标题和其他所有内容。

解决方案

看看

  .dialog-pane { 
-fx-border-color:black;
-fx-border-width:2.0px;
}

/ **按钮所在栏的成本化** /
.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:黄色;
-fx-text-fill:black;
-fx-font-size:15.0px;
}

/ ** 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;
}


/ **按钮的成本化** /
.dialog-pane .button {
-fx-background-color:black;
-fx-text-fill:white;
-fx-wrap-text:true;
-fx-effect:dropshadow(三遍,黄色,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;
}


Searching in caspian.css I found that I can customize dialog-pane.Alert extends Dialog so I tried some of of these lines of code:

.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.

解决方案

Take a look here how to add stylesheet or|and styleclass to DialogPane,so you can add your costume css file.

Example(picture + css code):

 .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; 
 }

这篇关于使用css自定义JavaFx警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆