ToggleSwitchSkin should override computeMaxWidth/Height

Issue #735 resolved
Christian Schudt
created an issue

ToggleSwitchSkin should override computeMaxWidth/Height like LabeledSkinBase does.

Otherwise it has Double.MAX_VALUE as max width / height and therefore you cannot align it to center.

    protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
        return getSkinnable().prefWidth(height);

    protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
        return getSkinnable().prefHeight(width);

Comments (7)

  1. Christian Schudt reporter


    sure, here.

    Expected behavior: It behaves like other Labeled controls (here: it's vertically centered within the HBox).

    import javafx.application.Application;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.CheckBox;
    import javafx.scene.control.TextArea;
    import javafx.scene.layout.HBox;
    import javafx.stage.Stage;
    import org.controlsfx.control.ToggleSwitch;
    public class TestApp3 extends Application {
        public static void main(String[] args) {
        public void start(Stage stage) {
            HBox hBox = new HBox();
            CheckBox checkBox = new CheckBox("CheckBox");
            checkBox.setStyle("-fx-border-color: red");
            hBox.getChildren().add(new TextArea());
            ToggleSwitch toggleSwitch = new ToggleSwitch();
            toggleSwitch.setStyle("-fx-border-color: red");
            stage.setScene(new Scene(hBox));
  2. SamirH

    Wow, have been a long time since I had not seen such a beautiful SSCCE, much appreciated!

    Allright I now see the problem, your solution seems to work. Would you be able to provide a pull request in order to fix that issue? Otherwise I'll do that later when my massive SpreadsheetView pull request will be accepted.

  3. Log in to comment