A
A
Anton @ Lyalin2017-04-12 08:32:42
JavaFX
Anton @ Lyalin, 2017-04-12 08:32:42

How to pass an ObservableList from another class to the controller?

There is a controller where you need to pass the ObservableList object from the Filter class:

public class FilterController implements Initializable{

    @FXML
    public TableView<DataFilter> tableView;

    @FXML
    public TableColumn<DataFilter, String> columnWord;

    @FXML
    public TableColumn<DataFilter, Integer> columnFrequency;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        columnWord.setCellValueFactory(new PropertyValueFactory<DataFilter, String>("word"));
        columnFrequency.setCellValueFactory(new PropertyValueFactory<DataFilter, Integer>("number"));

        tableView.setItems(?????);
    }
}

The Filter class in which the ObservableList object is created:
ObservableList<DataFilter> observableList(){
        ObservableList<DataFilter> observableList = FXCollections.observableArrayList();
        for (Object o : wordAndNumber().entrySet()) {
            Map.Entry entry = (Map.Entry) o;
            observableList.add(new DataFilter((String) entry.getKey(), (int) entry.getValue()));
        }
        return observableList;
    }

how do i do it if pass through:
Filter filter = new Filter();
tableView.setItems(filter.observableList())

that doesn't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-04-12
@red-barbarian

Filter is empty.
Everything is working.
Create a filter in another window, and call tableView.setItems from this window.
A window with a table must be created. Certainly.
A small note on the project.
Write tests. They clarify. There will be no such moments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question