简体   繁体   English

在JavaFX中调整ToggleButton的大小

[英]Resize ToggleButton in JavaFX

i have added a Radio Button into an HBox. 我已经在HBox中添加了单选按钮。 The problem is, that i can not resize the Radio Button... 问题是,我无法调整单选按钮的大小...

I dont have a caption for the Radio Button, i only need the Button. 我没有单选按钮的标题,我只需要按钮。 The Problem is that the Functions setPrefSize/setMaxSize/setMinSize not really change the radius / caliber. 问题在于,函数setPrefSize / setMaxSize / setMinSize不能真正改变半径/口径。

How can i change the Field - Size of the Radio Button and how can i change the radius/caliber? 如何更改字段-单选按钮的大小以及如何更改半径/口径?

At the moment, this is my code: 目前,这是我的代码:

//Configuration of the Radio-Button
    radio.setText("");
    radio.setMaxSize(8, 8);
    radio.setPrefSize(8, 8);
    radio.setMinSize(8, 8);
    radio.setStyle("-fx-padding:0;-fx-background-size:0; -fx-border-radius:13px; -fx-background-radius:13px;");
    radio.setSelected(false);
    radio.setVisible(check);
    addComponentToBox(radio);

Thanks for your help... 谢谢你的帮助...

I solve the problem. 我解决了问题。 If you want to style / resize only the dot or the radio you only have to do it like that: 如果您只想对点或收音机设置样式/调整大小,则只需这样做:

    .radio-button .radio {
        -fx-padding: 2px;
     }

     .radio-button .dot {
        -fx-padding: 2px;
     }

The padding will set the radius/caliber of the radio/dot! 填充将设置无线电/点的半径/口径!

as from stated in JavaFX CSS Reference Guide , you have to style also dot (which is a child node of style class radio-button . So my suggestion is to create a separate stylesheet (which supports modularisation, reuse and separation of concerns) and in your css do something like 正如《 JavaFX CSS参考指南》中所述 ,您还必须设置dot样式(这是样式类radio-button的子节点。因此,我的建议是创建一个单独的样式表(支持模块化,重用和关注点分离),并在你的CSS做类似的事情

.radio-button .radio {
    -fx-border-width: 3px;
    -fx-border-color: red;
    -fx-background-color: white;
    -fx-border-radius: 15px;
    -fx-padding: 10px;
}
.radio-button .radio:selected {
    -fx-background-color: white;
}
.radio-button -radio:armed {
    -fx-background-color: white;
}
.radio-button -radio:determinate {
    -fx-background-color: white;
}
.radio-button -radio:indeterminate {
    -fx-background-color: white;
}
.radio-button .dot {
    -fx-background-radius: 15px;
    -fx-padding: 12px;
}
.radio-button:selected .radio .dot {
    -fx-background-color: red;
}

I exaggerated a bit with the styling :-) 我对样式有点夸张了:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM