Align a label with textarea

1.1k views Asked by At

How can I align the position of my "Description" label such that it corresponds in line with the "Enter description" text (Label - TextArea). These components are inside an gridPane and coded in javaFX ( so no Scene Builder tips can help me here ). Code:

Label descriptionLabel = new Label("Description:");
descriptionLabel.setPadding(new Insets(5, 5, 5, 5));
JFXTextArea descriptionTextArea = new JFXTextArea();
descriptionTextArea.setPadding(new Insets(5, 0, 5, 0));
descriptionTextArea.setPromptText("Enter description...");
gridPane.add(descriptionLabel, 0, 2);
gridPane.add(descriptionTextArea, 1, 2);

I've tried with descriptionLabel.setAlignment(Pos.TOP_LEFT); but neither that helped me out

1

There are 1 answers

0
SedJ601 On BEST ANSWER

You have to use GridPane Constraints. Valignment set to Top and Halignment set to Right. Java Doc

GridPane.setHalignment(descriptionLabel, HPos.RIGHT);
GridPane.setValignment(descriptionLabel, VPos.TOP);

After looking at you picture again, I think you only need setValignment.