A
A
Anton @ Lyalin2017-04-10 17:25:41
JavaFX
Anton @ Lyalin, 2017-04-10 17:25:41

Why doesn't the code below work?

This code works, displays data in a table.

public class FilterController{

    @FXML
    public TableView<DataFilter> tableView;

    @FXML
    public TableColumn<DataFilter, String> columnWord;

    @FXML
    public TableColumn<DataFilter, Integer> columnFrequency;

    @FXML
    public void initialize() {


        columnWord.setCellValueFactory(new PropertyValueFactory<DataFilter, String>("word"));
        columnFrequency.setCellValueFactory(new PropertyValueFactory<DataFilter, Integer>("number"));

        tableView.setItems(data());

    }

    ObservableList<DataFilter> data(){
        ObservableList<DataFilter> list = FXCollections.observableArrayList();
        list.add(new DataFilter("город", 1));
        return list;
    }
}

And this code does not work
Although I need this option
public class FilterController{

    @FXML
    public TableView<DataFilter> tableView;

    @FXML
    public TableColumn<DataFilter, String> columnWord;

    @FXML
    public TableColumn<DataFilter, Integer> columnFrequency;

    @FXML
    public void initialize() {


        columnWord.setCellValueFactory(new PropertyValueFactory<DataFilter, String>("word"));
        columnFrequency.setCellValueFactory(new PropertyValueFactory<DataFilter, Integer>("number"));

        tableView.setItems(data());

    }

    ObservableList<DataFilter> data(){
        ObservableList<DataFilter> list = FXCollections.observableArrayList();
        Filter filter = new Filter();
        return filter.observableList();
    }
}

Here I create a sheet in the Filter class, then I pass it to the newly created element. But it doesn't work.

Answer the question

In order to leave comments, you need to log in

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

public class FilterController implements Initializable ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question