7

我尝试使用 FXML 和 CSS 更改我的应用程序构建中的单选按钮大小。我使用场景生成器。

谢谢你的帮助 !

这是我的单选按钮的实际 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  ;
}
4

1 回答 1

10

-fx-padding: 10px;

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

来自JavaFX CSS 参考指南

例子:

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

无线电.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 单选按钮

有关更多鼓舞人心的 JavaFX CSS 主题,请查看GreggSetzer /JavaFX-CSS-Themes 的win7glass.css

于 2012-08-20T14:55:18.933 回答