Search code examples
javafxresizablescrollpane

How to block a ScrollPane panel JavaFX


I have a small problem. I'm building an interface with JavaFX like this: interface JavaFX I wonder, how can I do to block those "lines" of the ScrollPane I indicated in the image? Practically it is not to be resizable but among its properties the ScrollPane does not allow me to put the check on that property:

Properties

How can I do to solve? thanks to all in advance!


Solution

  • I think your problem is that you have not added a minimum value to your ScrollPanes here's an example :

        SplitPane split = new SplitPane();
        split.setPrefSize(400, 400); 
    
        //First ScrollPane
        ScrollPane spA = new ScrollPane();
        spA.setMinWidth(100);  //Block the scrollPane width to 100
        spA.setFitToHeight(true);
        spA.setFitToWidth(true); 
        Pane paneA = new Pane();
        paneA.setStyle("-fx-background-color:red;");
        spA.setContent(paneA);
    
        //Second ScrollPane
        ScrollPane spB = new ScrollPane();
        spB.setMinWidth(100); //Block the scrollPane width to 100
        spB.setFitToHeight(true);
        spB.setFitToWidth(true); 
        Pane paneB = new Pane();
        paneB.setStyle("-fx-background-color:blue;");
        spB.setContent(paneB);
    
        split.getItems().addAll(spA,spB);
    

    To be able to use your scrollPane as it grows, you can use the binding and bind the content's (width/height properties) of your ScrollPane to their parents (ScrollPane) example :

    //set the (FitToHeight/FitToWidth) properties to false before !
    spA.widthProperty().addListener(new ChangeListener<Number>() {
    
            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
    
                paneB.setMinWidth((double)newValue);
            }
        });
    

    Good luck !