public void start(Stage stage) { stage.setTitle("ListView demo"); FlowPane rootNode = new FlowPane(10, 10); rootNode.setAlignment(Pos.CENTER); Scene scene = new Scene(rootNode, 200, 120); stage.setScene(scene); responseLabel = new Label("Select Transport Type"); ObservableList<String> transportTypes = FXCollections.observableArrayList("Train", "Car", "Airplane"); ListView<String> transportListView = new ListView(transportTypes); transportListView.setPrefSize(80, 80); MultipleSelectionModel<String> listViewSelectionModel = transportListView.getSelectionModel(); listViewSelectionModel .selectedItemProperty() .addListener( new ChangeListener<String>() { public void changed( ObservableValue<? extends String> changed, String oldValue, String newValue) { responseLabel.setText("Transport selected is " + newValue); } }); rootNode.getChildren().addAll(transportListView, responseLabel); stage.show(); }
@Inject public FileDetailsCtrl(FileNavigationState navState) { this.navState = navState; this.navState.selectedFileProperty().addListener(new SelectedFileListener()); listFiles = FXCollections.observableList(new ArrayList<>()); fileDetails = FXCollections.observableList(new ArrayList<>()); fileGrid.setCellHeight(80); fileGrid.setCellWidth(100); fileGrid.getItems().addAll(listFiles); fileDetailsList.getItems().addAll(fileDetails); }