I work with TableView (two columns) in JavaFX, created a constructor and pass in the initial data. In the first type of String, in the second Integer, I did everything privately, but everything works with the string, but not with Integer. Help me figure out exactly what I'm missing.

Main class where I fill in the initial data

private ObservableList<TableIncome> incomeData = FXCollections.observableArrayList(); public Main() { // В качестве образца добавляем некоторые данные incomeData.add(new TableIncome("Доход1", 0)); incomeData.add(new TableIncome("Доход2", 0)); incomeData.add(new TableIncome("Доход3", 0)); } 

Here is the controller class, where I declare some variables and fill the table.

  @FXML private TableView<TableIncome> tableIncomeTableView; @FXML private TableColumn<TableIncome, String> typeIncome; @FXML private TableColumn<TableIncome, Integer> janIncome; @FXML private void initialize() { // Инициализация таблицы адресатов с двумя столбцами. typeIncome.setCellValueFactory(cellData -> cellData.getValue().typeProperty()); janIncome.setCellValueFactory(cellData -> cellData.getValue().januaryProperty()); } 

And the TableIncome class itself, where the constructor is located.

 public class TableIncome { private StringProperty type; private IntegerProperty january; public TableIncome(String type, Integer january){ this.type = new SimpleStringProperty (type); this.january = new SimpleIntegerProperty(january); } public StringProperty typeProperty() { return type; } public IntegerProperty januaryProperty() { return january; } 

Those. the error itself points to cellData.getValue().januaryProperty()); , with Bad return type in lambda expression: IntegerProperty cannot be converted to ObservableValue<Integer> error text Bad return type in lambda expression: IntegerProperty cannot be converted to ObservableValue<Integer>

Class TableIncome

 import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; /** * Хранение данных для таблицы "Тип дохода" */ public class TableIncome { private StringProperty type; private IntegerProperty january; private IntegerProperty february; private IntegerProperty march; private IntegerProperty april; private IntegerProperty may; private IntegerProperty june; private IntegerProperty jule; private IntegerProperty august; private IntegerProperty september; private IntegerProperty october; private IntegerProperty november; private IntegerProperty december; public TableIncome(){ this(null, null); } /** * Конструктор с начальными данными * @param type */ public TableIncome(String type, Integer january){ this.type = new SimpleStringProperty (type); this.january = new SimpleIntegerProperty(january); /** * начальные данные */ // this.january = new SimpleIntegerProperty(0); this.february = new SimpleIntegerProperty (0); this.march = new SimpleIntegerProperty (0); this.april = new SimpleIntegerProperty (0); this.may = new SimpleIntegerProperty (0); this.june = new SimpleIntegerProperty (0); this.jule = new SimpleIntegerProperty (0); this.august = new SimpleIntegerProperty (0); this.september = new SimpleIntegerProperty (0); this.october = new SimpleIntegerProperty (0); this.november = new SimpleIntegerProperty (0); this.december = new SimpleIntegerProperty (0); } public String getType() { return type.get(); } public StringProperty typeProperty() { return type; } public void setType(String type) { this.type.set(type); } public int getJanuary() { return january.get(); } public IntegerProperty januaryProperty() { return january; } public void setJanuary(int january) { this.january.set(january); } public int getFebruary() { return february.get(); } public IntegerProperty februaryProperty() { return february; } public void setFebruary(int february) { this.february.set(february); } public int getMarch() { return march.get(); } public IntegerProperty marchProperty() { return march; } public void setMarch(int march) { this.march.set(march); } public int getApril() { return april.get(); } public IntegerProperty aprilProperty() { return april; } public void setApril(int april) { this.april.set(april); } public int getMay() { return may.get(); } public IntegerProperty mayProperty() { return may; } public void setMay(int may) { this.may.set(may); } public int getJune() { return june.get(); } public IntegerProperty juneProperty() { return june; } public void setJune(int june) { this.june.set(june); } public int getJule() { return jule.get(); } public IntegerProperty juleProperty() { return jule; } public void setJule(int jule) { this.jule.set(jule); } public int getAugust() { return august.get(); } public IntegerProperty augustProperty() { return august; } public void setAugust(int august) { this.august.set(august); } public int getSeptember() { return september.get(); } public IntegerProperty septemberProperty() { return september; } public void setSeptember(int september) { this.september.set(september); } public int getOctober() { return october.get(); } public IntegerProperty octoberProperty() { return october; } public void setOctober(int october) { this.october.set(october); } public int getNovember() { return november.get(); } public IntegerProperty novemberProperty() { return november; } public void setNovember(int november) { this.november.set(november); } public int getDecember() { return december.get(); } public IntegerProperty decemberProperty() { return december; } public void setDecember(int december) { this.december.set(december); } } 
  • Give class IntegerProperty . In lamda you need an integer value, maybe it is stored in an IntegerProperty . - Anton Sorokin
  • I agree, I would also remove Property in the POJO, it is already observable in you, so also inside it is treated with oil. - Maxim
  • @Maxim I understand correctly, what do you suggest in the januaryProperty to leave the type just Integer ? Well and accordingly to alter private IntegerProperty january; where the type will be just an Integer ? I just tried it, it didn't work out, and why does everything work with String? - Vladislav Zherikhov 5:27 pm
  • @AntonSorokin sorry, I didn’t quite understand, you are writing - “Bring a class”, in the sense of putting it out completely? - Vladislav Zherikhov pm
  • 2
    If the answers do not offer anything sensible, change the TableColumn<TableIncome, Integer> janIncome Integer to Number in TableColumn<TableIncome, Integer> janIncome or add getters and setters to the POJO and use PropertyValueFactory ( example ). - zRrr 7:52 pm

0