Javafx 2.0 : How to change the size of the radio-buttons circle with CSS?

前端 未结 1 1849
暖寄归人
暖寄归人 2021-01-12 17:10

I try to change the radio-buttons size in my app build with FXML and CSS. I use the sceneBuilder.

Thanks for your help !

Here is my actual CSS code for the r

相关标签:
1条回答
  • 2021-01-12 17:50

    -fx-padding: 10px;

    A single padding value means that all padding are the same, if a set of four padding values is specified, they are used for the top, right, bottom, and left edges of the region.

    from the JavaFX CSS Reference Guide

    Example:

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

    result

    Styled JavaFX RadioButton

    For more inspirational JavaFX CSS themes, check win7glass.css from GreggSetzer/JavaFX-CSS-Themes

    0 讨论(0)
提交回复
热议问题