Set maxHeight to alert javafx with scrollpane

I have a javafx warning that has a ScrollPane. Inside ScrollPane, I load a grid, the size of which may vary depending on the content. As such, the warning grows with the contents of the GridPane. I use GridPane so that the warning does not exceed the screen size of the application and allows scrolling. But that does not work. Instead, the warning increases to the size I set.

Here is my code:

ScrollPane scroll = new ScrollPane();
scroll.setContent(gridpane);
scroll.setMaxHeight(500);
alert.getDialogPane().setContent(scroll);

where alert is an instance of the javafx Alert class, and gridpane has content that is added dynamically.

gridpaneis an instance CustomGridthat is defined as follows:

  public class CustomGrid extends GridPane{

    public CustomGrid() {
        this.setHgap(20);
        this.setVgap(20);

        ColumnConstraints firstColConstraints =  new ColumnConstraints();
        firstColConstraints.setHalignment(HPos.RIGHT);
        firstColConstraints.setPercentWidth(50.0);
        firstColConstraints.setHgrow(Priority.ALWAYS);
        ColumnConstraints secondColConstraints =  new ColumnConstraints();
        ColumnConstraints thirdColConstraints =  new ColumnConstraints();
        thirdColConstraints.setHgrow(Priority.ALWAYS);

        this.getColumnConstraints().addAll(firstColConstraints, secondColConstraints, thirdColConstraints);
    }
}
+4

Source: https://habr.com/ru/post/1675354/


All Articles