【问题标题】:Javafx 2.0 : How to change the size of the radio-buttons circle with CSS?Javafx 2.0:如何使用 CSS 更改单选按钮圆圈的大小?
【发布时间】:2012-08-15 19:32:01
【问题描述】:

我尝试使用 FXML 和 CSS 在我的应用构建中更改单选按钮的大小。 我用的是sceneBuilder。

感谢您的帮助!

这是我的单选按钮的实际 CSS 代码:

.radio-button .radio{
-fx-border-width     : 1px   ;
-fx-border-color     : #000  ;
-fx-background-color : white ;
-fx-background-image : null  ;
-fx-border-radius    : 15px  ;
-fx-height           : 15px  ; /* Not working */
height               : 5px   ; /* Not working */
}
.radio-button .radio:selected{
-fx-background-color : white ;
-fx-background-image : null  ;
}
.radio-button -radio:armed{
-fx-background-color : white ;
-fx-background-image : null  ;
}
.radio-button -radio:determinate{
-fx-background-color : white ;
-fx-background-image : null  ;
}
.radio-button -radio:indeterminate{
-fx-background-color : white ;
-fx-background-image : null  ;
}

【问题讨论】:

    标签: javafx javafx-2 fxml scenebuilder


    【解决方案1】:

    -fx-padding: 10px;

    单个填充值表示所有填充相同,如果指定一组四个填充值,则它们用于区域的顶部、右侧、底部和左侧边缘。

    来自JavaFX CSS Reference Guide

    例子:

    CssTest.java

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.RadioButton;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    
    public class CssTest extends Application 
    {
        public void start(Stage stage) throws Exception
        {
            BorderPane root = new BorderPane();
            RadioButton radio = new RadioButton("radio-text");
            root.setCenter(radio);
            root.getStylesheets().add(getClass().getResource("/radio.css").toExternalForm());
            stage.setScene(new Scene(root));
            stage.show();
        }
    
        public static void main(String[] args)
        {
            launch(args);
        }
    }
    

    radio.css

    .radio-button .radio {
        -fx-border-width: 1px;
        -fx-border-color: #000;
        -fx-background-color: white;
        -fx-background-image: null;
        -fx-border-radius: 15px;
        -fx-padding: 4px;
    }
    .radio-button .radio:selected {
        -fx-background-color: white;
        -fx-background-image: null;
    }
    .radio-button -radio:armed {
        -fx-background-color: white;
        -fx-background-image: null;
    }
    .radio-button -radio:determinate {
        -fx-background-color: white;
        -fx-background-image: null;
    }
    .radio-button -radio:indeterminate {
        -fx-background-color: white;
        -fx-background-image: null;
    }
    .radio-button .dot {
        -fx-background-radius: 15px;
        -fx-padding: 8px;
    }
    

    结果

    如需更多鼓舞人心的 JavaFX CSS 主题,请查看来自GreggSetzer/JavaFX-CSS-Themes

    win7glass.css

    【讨论】:

    • 谢谢,但它不能帮助我更改复选框和单选按钮的大小
    • 衷心感谢您!
    猜你喜欢
    • 2011-06-22
    • 1970-01-01
    • 2022-12-12
    • 1970-01-01
    • 2020-08-20
    • 2013-04-25
    • 2015-01-06
    • 2020-05-22
    相关资源
    最近更新 更多