1

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 !

Community
  • 1
  • 1
neuronsoverflow
  • 133
  • 4
  • 14

1 Answers1

3

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.

WillBD
  • 1,919
  • 1
  • 18
  • 26
  • Thank you for your fast reply. I think I have succeeded for one time but the Pane was 100px height, so I changed it and therefore I can't get it working a second time. But I always notice that rows are not getting smaller and smaller; there are not added at all... I'll play a little bit on this and I'll get back to you if I succeed with your answer. – neuronsoverflow Jun 10 '14 at 18:47
  • Finnaly i do not succeed to have a beautiful layout on the inner gridpane (first row too much taller) but I'll play a little to fit it perfectly. And you were right it's by playing with some "fertVbox.setMinHeight(fertGridPaneNumLines*20+200); fertGridPane.setMinHeight(fertGridPaneNumLines*20+200);" and i get it working !! Many thanks !! – neuronsoverflow Jun 10 '14 at 19:03