JavaFX-Integer w TableColum

0

Witam
Chcę sobie przedstawić liste obiektów w formie Tabelki (TableView) robiąc to tak:

 @FXML
private TableColumn<Answer, Integer> nextSituationIdColumn;

@FXML
private void initialize(){
	nextSituationIdColumn.setCellValueFactory(cellData -> cellData.getValue().nextSituationIdProperty()); //i w tym miejscu wywala błąd
}

Błąd treści
Type mismatch: cannot convert from IntegerProperty to ObservableValue<Integer>

Jest to troche dziwne ponieważ jeśli poda mu sie StringProperty to działa normalnie. Jest jakaś łatwa metoda żeby to obejść i móc wyświetlać inty w columnie?

0

Spróbuj tak:
nextSituationIdColumn.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().nextSituationIdProperty().get()));
Piszę bez sprawdzenia, ale coś w tym stylu powinno pomóc.

Wrzuć jak wygląda twoja klasa Answer

0

Klasa Answer

public class Answer {

	private StringProperty text;
	private IntegerProperty id;
	private IntegerProperty nextSituationId;

	public Answer(String text, int id, int nextSituationId) {
		this.text = new SimpleStringProperty(text);
		this.id = new SimpleIntegerProperty(id);
		this.nextSituationId = new SimpleIntegerProperty(nextSituationId);
	}

	public String getText(){
		return text.get();
	}

	public void setText(String text){
		this.text.set(text);
	}

	public StringProperty textProperty(){
		return text;
	}

	public int getId(){
		return id.get();
	}

	public void setId(int id){
		this.id.set(id);
	}

	public IntegerProperty idProperty(){
		return id;
	}

	public int getNextSituationId(){
		return nextSituationId.get();
	}

	public void setNextSituationId(int id){
		this.nextSituationId.set(id);
	}

	public IntegerProperty nextSituationIdProperty(){
		return nextSituationId;
	}
} 
0

Dzisiaj sprawdziłem jak to w projekcie robiłem w pracy. U mnie analogicznie do twojego przykładu w taki sposób przypisywałem :

 
nextSituationIdColumn.setCellValueFactory(cellData -> new PropertyValueFactory<Answer,Integer>("nextSituationId")); 
nextSituationIdColumn.setCellFactory(TextFieldTableCell.<Answer, Integer>forTableColumn(new IntegerStringConverter())); //potrzebne jeżeli dane będą modyfikowane w tabeli

1 użytkowników online, w tym zalogowanych: 0, gości: 1