Answer the question
In order to leave comments, you need to log in
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(?????);
}
}
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;
}
Filter filter = new Filter();
tableView.setItems(filter.observableList())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question