package tests; import java.util.ArrayList; import java.util.Collections; import javafx.application.Application; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TestVBoxUpdate extends Application { @Override public void start(final Stage stage) { stage.setTitle("Sample"); Scene scene = new Scene(new Group(), 500, 500); final VBox labels = new VBox(5); final Label label1 = new Label("Label 1"); final Label label2 = new Label("Label 2"); labels.getChildren().addAll(label1, label2); final Button swapButton = new Button("Swap"); swapButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { labels.getChildren().setAll(label2, label1); } }); VBox vbox = new VBox(20); vbox.getChildren().addAll(labels, swapButton); Group root = (Group) scene.getRoot(); root.getChildren().clear(); root.getChildren().add(vbox); stage.setScene(scene); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } }