有没有办法在特定位置插入 children ?
Is there a way to insert children at specific position?
那是我的 fxml 的一部分:
<VBox>
<children>
<Button/>
<Button/>
</children>
</VBox>
我想向 vBox 添加一个新的 child。但我想将它添加到特定位置,例如在两个按钮 "at position 2".
之间
窗格的子列表是 ObservableList
,它只是普通旧 java.util.List
的子界面。所以你可以访问所有常用的list methods。假设您在控制器中引用了 VBox
,将其命名为 vbox
,您只需执行
vbox.getChildren().add(1, myNewButton);
那是我的 fxml 的一部分:
<VBox>
<children>
<Button/>
<Button/>
</children>
</VBox>
我想向 vBox 添加一个新的 child。但我想将它添加到特定位置,例如在两个按钮 "at position 2".
之间窗格的子列表是 ObservableList
,它只是普通旧 java.util.List
的子界面。所以你可以访问所有常用的list methods。假设您在控制器中引用了 VBox
,将其命名为 vbox
,您只需执行
vbox.getChildren().add(1, myNewButton);