Search code examples
javajavafxgridpane

Autoscale a String to the width of a screen


I'm trying to show a String on the screen, which is implemented in the Label named vraagLabel. I have placed the String in a Javafx.Gridpane and placed the GridPane within a Javafx.Borderpane.

The issue I'm having is that when the String is too big, since my screen has to have a set height and width, it will not continue on the next line but will only show ... How can I make it scale, so that the entire String will be shown on the screen, so when the String reaches the limit of the screen it will continue on the next line.

public class VraagView extends BorderPane {
javafx.scene.image.Image afbeeldingVraag = new javafx.scene.image.Image("be/kdg/TrivialPursuit/afbeeldingen/Vraag_Kaart.jpg");
private javafx.scene.control.Label vraagLabel;
private TextField antwoordField;
private Button btncheck;
private GridPane grid;

public VraagView( ) {
    initialiseNodes();
    layoutNodes();
}


private void initialiseNodes( ) {
    vraagLabel = new Label();
    antwoordField = new TextField();
    btncheck = new Button("Antwoord");
    grid = new GridPane();
}

private void layoutNodes() {
    setBackground(new Background(new BackgroundImage(afbeeldingVraag, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT)));
    grid.setVgap(5);
    grid.setHgap(5);
    grid.add(vraagLabel, 0, 5);
    grid.add(antwoordField, 1, 1);
    grid.add(btncheck, 2, 2);
    setCenter(grid);
    grid.setGridLinesVisible(true);
} 

Solution

  • Instead of a TextField you could use a TextArea and set its wrapText attribute to true.