0

I want to add dynamically labels to a pane :

for (int k = 0; k < traitement.quad.lqua.size(); k++) 
{
  Label l = new Label();
  l.setText(traitement.quad.lqua.get(k));
  apane.getChildren().add(l);
}

here is the result : enter image description here

i don't want to have them in the same place i want to have one label by ligne , so where is the issue ?

3
  • What is the type of apane? Commented Jan 17, 2016 at 20:04
  • And the AnchorPane is the white area where the labels are added? Is there anything else, that will be added to that pane? Commented Jan 17, 2016 at 20:10
  • yes it's the white area .. no i want to add just labels Commented Jan 17, 2016 at 20:12

1 Answer 1

1

Replace the AnchorPane with a VBox. That way all the labels will be added one below another.

AnchorPane manages the layouting of the children according to the anchor, which in your case seems to be top left. This works well if there is only one child, but will result in a mess if there are more.

In my personal experience I find AnchorPane not very useful when it comes to designing complex user interface. I usually en up using a Group or Pane instead and handle the layouting myself.

Sign up to request clarification or add additional context in comments.

3 Comments

i have an exception : Caused by: java.lang.NullPointerException in this ligne : apane.getChildren().add(l);
That is probably because apane is not initialized before adding the child node.
no this is not the probleme i have try to add in fxml code a label it's shown by the one that i have add dynamically does not appear

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.