Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 JavaFX 应用程序,其中显示从 node.js 服务器接收到的信息。在某一时刻,当它接收到特定字符串“new_game”时,它应该重新加载 HBox 内的 4 个 VBox。程序启动后是否可以删除旧的 VBox 并放入新的 VBox?
(仅供参考,我问这个是因为更新 VBoxes 会因为我的 nooby 代码而有点麻烦。)
所以你想删除旧的 vBox 并添加新的我会使用其中的一些:
hBox.getChildren().clear();
将删除此 hbox 的所有内容,因此如果您只想删除 4 个特定的 vbox,请使用以下命令:
hBox.getChildren().remove(vBox1, vBox2, vBox3, vBox4);
然后你想添加新的 vbox,这样做
hBox.getChildren().addAll(newVBox1, newVBox2, newVBox3, newVBox4);
我希望这回答了你的问题