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();
  }
示例#2
0
  public static ObservableList<String> getResourceOutIcons() {
    // TODO do this better!
    ObservableList<String> names = FXCollections.observableArrayList();

    Arrays.asList(new File(ICON_OUT_FOLDER).listFiles())
        .forEach(
            f -> {
              names.add(f.getName());
            });

    return names;
  }