[英]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);
}
i don't want to have them in the same place i want to have one label by ligne , so where is the issue ? 我不想把它们放在同一个地方,我想用ligne贴一个标签,那么问题出在哪里呢?
Replace the AnchorPane
with a VBox
. 用
VBox
替换AnchorPane
。 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. AnchorPane
根据锚点管理子项的布局,在您的情况下,锚点似乎位于左上方。 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. 根据我的个人经验,我发现
AnchorPane
在设计复杂的用户界面时不是很有用。 I usually en up using a Group
or Pane
instead and handle the layouting myself. 我通常会改用
Group
或Pane
来自己处理布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.