使用场景生成器 8.5.0 自定义 java8 个单选按钮

Customising java8 radio buttons using scene builder 8.5.0

我正在尝试创建一个程序,颜色对我很重要,我的问题是如何自定义单选按钮(更改蓝色圆圈并更改选定的灰色圆圈和白色圆圈)enter image description here

最简单的方法是在 css 中进行样式设置。您可以查看 modena.css(javafx 的基础 css 文件)。将您需要的部分复制到您的 css 文件并根据需要编辑值。

https://gist.github.com/maxd/63691840fc372f22f470 -> 来自第 749 行

/*******************************************************************************
 *                                                                             *
 * RadioButton                                                                 *
 *                                                                             *
 ******************************************************************************/

.radio-button {
    -fx-label-padding: 0.0em 0.0em 0.0em 0.416667em; /* 0 0 0 5 */
    -fx-text-fill: -fx-text-background-color;
}
.radio-button > .radio,
.radio-button:focused > .radio  {
   -fx-background-radius: 1.0em; /* large value to make sure this remains circular */
   -fx-padding: 0.333333em; /* 4 -- padding from outside edge to the inner black dot */
}
.radio-button > .radio > .dot {
   -fx-background-color: transparent;
   -fx-background-radius: 1.0em; /* large value to make sure this remains circular */
   -fx-padding: 0.333333em; /* 4 -- radius of the inner black dot when selected */
}

请注意单选按钮扩展了其他 ui 类。参考 guide 可以帮助您理解层次结构:https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#radiobutton