List of usage examples for javafx.scene.layout GridPane setConstraints
public static void setConstraints(Node child, int columnIndex, int rowIndex, int columnspan, int rowspan, HPos halignment, VPos valignment)
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("ObservableLists"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10);//from ww w . j a va2 s . co m gridpane.setVgap(10); Label candidatesLbl = new Label("Left"); GridPane.setHalignment(candidatesLbl, HPos.CENTER); gridpane.add(candidatesLbl, 0, 0); Label heroesLbl = new Label("Right"); gridpane.add(heroesLbl, 2, 0); GridPane.setHalignment(heroesLbl, HPos.CENTER); final ObservableList<String> lefts = FXCollections.observableArrayList("A", "B", "C"); final ListView<String> leftListView = new ListView<String>(lefts); leftListView.setPrefWidth(150); leftListView.setPrefHeight(150); gridpane.add(leftListView, 0, 1); final ObservableList<String> rights = FXCollections.observableArrayList(); final ListView<String> rightListView = new ListView<String>(rights); rightListView.setPrefWidth(150); rightListView.setPrefHeight(150); gridpane.add(rightListView, 2, 1); Button sendRightButton = new Button(">"); sendRightButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { String item = leftListView.getSelectionModel().getSelectedItem(); if (item != null) { leftListView.getSelectionModel().clearSelection(); lefts.remove(item); rights.add(item); } } }); Button sendLeftButton = new Button("<"); sendLeftButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { String item = rightListView.getSelectionModel().getSelectedItem(); if (item != null) { rightListView.getSelectionModel().clearSelection(); rights.remove(item); lefts.add(item); } } }); VBox vbox = new VBox(5); vbox.getChildren().addAll(sendRightButton, sendLeftButton); gridpane.add(vbox, 1, 1); GridPane.setConstraints(vbox, 1, 1, 1, 2, HPos.CENTER, VPos.CENTER); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }