JavaFX GridPane inside ScrollPane inside GridPane can't set ScrollPane Growing


Question

Hi all !

I've got a simple question: I'm using FXML files and I've done this layout:

I am trying to expand the height of the Scrollpane inside the column 1 (row span 3) GridContainer

With this hierarchy: (top GridPane controller is hightlighted - it is inside a VBox)

Hierarchy

And the target ScrollPane closer view: enter image description here

My problem is that I'm adding dynamically rows to the GridPane inside the ScrollPane (inside the other GridPane container); and I can't add more than 3 columns (size of the Vbox container apparently) but if I remove the scrollpane i can add as many rows that I wan't but rows are disapearing as they are outside of the Vbox/GridPane scope...

Is it possible to do what I wan't (GridPane inside ScrollPane inside mutliple GridPane rows)? I thought it will work "out of the box" but it seems that is really not :-(

Is this because of the ScrollPane Max/Min (I played with all size of containers and/or top-containers -Vbox and ScrollPane- without success...) Or is this because the GridPane parent has max height set and is blocking ScrollPane height growth ?

I have tried this post solution :How to scroll to make a Node within the content of a ScrollPane visible? without any success :-(

Any ideas ? Regards to all !

1
0
5/23/2017 11:49:34 AM

Accepted Answer

To answer the question in the middle of the post of "is it possible to do what I want (GridPane inside ScrollPane inside GridPane)" sure! here's the fxml code for it (don't mind the constants, I just threw it together in scene builder):

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
<children><ScrollPane prefHeight="200.0" prefWidth="200.0">
<content><GridPane prefHeight="132.0" prefWidth="297.0">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
</GridPane>
</content></ScrollPane>
</children>
</GridPane>

the trick to making it so you have a scrollbar with extra rows/columns without making all of the existing rows smaller, is to adjust the height of the innermost gridpane every time you dynamically add a row, this will ensure that the gridpane out-sizes the scrollpane and therefore makes it so the scrollpane 'scrolls'

ex something like (pseudo-code):

onButtonPress{
    resizeGridPane(sizeOfRow+paddingBetweenRows);
    AddRowInDesiredLocation(location);
}

I think that will give you the desired effect.

EDIT

After noticing your vbox which is inside the scrollpane which is inside the gridpane, you'll have to resize both the vbox and the grid pane appropriately to see the 'scrolling' effect of the scrollpane come around, if you only resize the grid pane, you'll simply get rows which are consecutively smaller and smaller.

2
6/10/2014 5:32:34 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon