Issue #735 resolved

ToggleSwitchSkin should override computeMaxWidth/Height

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.

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

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

Comments (7)

  1. Christian Schudt reporter

    Hi,

    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) {
            launch(args);
        }
    
        @Override
        public void start(Stage stage) {
    
            HBox hBox = new HBox();
            hBox.setAlignment(Pos.CENTER);
    
            CheckBox checkBox = new CheckBox("CheckBox");
            checkBox.setStyle("-fx-border-color: red");
            hBox.getChildren().add(checkBox);
            hBox.getChildren().add(new TextArea());
    
            ToggleSwitch toggleSwitch = new ToggleSwitch();
            toggleSwitch.setStyle("-fx-border-color: red");
            hBox.getChildren().add(toggleSwitch);
    
            stage.setScene(new Scene(hBox));
            stage.show();
        }
    }
    
  2. Samir Hadzic

    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