java - 使用 css 自定义 JavaFx Alert

标签 java css javafx

<分区>

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

.....

但没有任何变化。

问题: 我怎样才能做到这一点?我的意思是我想自定义背景、按钮、标题和其他所有内容。

最佳答案

看看here如何将样式表或|和styleclass添加到DialogPane,以便您可以添加您的服装css文件。

示例(图片+css代码):

enter image description here

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

关于java - 使用 css 自定义 JavaFx Alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37354686/

相关文章:

css - 网格系统中的 Bootstrap 白中断

html - Bootstrap 3 : Having problems modifying the navbar

java - 在现有 GUI 中播放 mp4 剪辑

animation - 在 JavaFX 中,如何在屏幕上移动 Sprite ?

java - 在java中如果 "char c = ' a' "why does "c = c + 1“无法编译?

java - hibernate : Downside of merge() over update()

java - 想要用java创建验证码

Java - 将 JLabel 解析为 java.util.Date

css - Bootstrap .nav-tabs border-bottom 不会消失

JavaFX TableView 具有两个固定列,最后一个列占用可用空间