首页 > 解决方案 > 使用场景构建器 8.5.0 自定义 java8 单选按钮

问题描述

我正在尝试创建一个程序,颜色对我很重要,我的问题是如何自定义单选按钮(更改蓝色环并更改选定的灰色圆圈和白色环)在此处输入图像描述

标签: javajavafxradio-buttonscenebuilder

解决方案


最简单的是在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 */
}

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


推荐阅读