Abderrahmane Mechri
Abderrahmane Mechri

Reputation: 89

how to add dynamically nodes to pane in javafx

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 ?

Upvotes: 0

Views: 2394

Answers (1)

hotzst
hotzst

Reputation: 7526

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.

Upvotes: 1

Related Questions