Je suis en train d'écrire un programme en utilisant JavaFX dans lequel jescrollpane ne redimensionne pas pour s'adapter gridpane JavaFX
Borderpane -> Centre -> VBox -> ScrollPane-> Gridpane
Je voudrais pouvoir pour ajouter autant de lignes à la grille que je le souhaite et que le scrollpane s'étende automatiquement.
Remarque: J'ai des fichiers très longs, donc j'ai seulement inclus les bits importants. Si vous avez besoin de tout le fichier FXML ou Controller, laissez moi un commentaire.
Voici le FXML pour mon gridpane/scrollpane:
<BorderPane>
<center>
<VBox>
<children>
<ScrollPane fx:id="messageScrollPane" vbarPolicy="ALWAYS" hbarPolicy="NEVER" hmax="0.0" vmax="0.0">
<content>
<GridPane fx:id="messageBox" prefHeight="540.0" prefWidth="589.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
</rowConstraints>
</GridPane>
</content>
</ScrollPane>
</children>
</VBox>
</center>
</BorderPane>
J'ai le code suivant à l'intérieur de mon contrôleur pour le FXML
@FXML
private GridPane messageBox;
if (me.getMail().size() > 0) {
for (int i = 0; i < me.getMail().size(); i++) {
messageBox.add(new Label(me.getMail().get(i).toString()), 0, rowNum);
rowNum++;
}
}
Merci à tous pour votre aide!
Ryan
J'ai écrit une simple description de la 'ScrollPane' dans la documentation, essayez de l'utiliser, (en espérant qu'il vous aidera), [ici] (http: // stackoverflow.com/documentation/javafx/8259/scrollpane/26534/b-dynamic-contents-size#t=201702022233434993017) –