У меня есть TableView людей:
<TableView fx:id="table" editable="true" focusTraversable="false" prefHeight="-1.0" prefWidth="-1.0" tableMenuButtonVisible="false" VBox.vgrow="ALWAYS">
<columns>
<TableColumn editable="false" maxWidth="5000.0" minWidth="10.0" prefWidth="100.0" resizable="false" sortable="false" style="-fx-font-size: 13pt;" text="Address">
<cellValueFactory>
<PropertyValueFactory property="id" />
</cellValueFactory>
</TableColumn>
<TableColumn editable="false" maxWidth="5000.0" minWidth="10.0" prefWidth="200.0" resizable="false" sortable="false" style="-fx-font-size: 13pt;" text="Address Type">
<cellValueFactory>
<PropertyValueFactory property="range" />
</cellValueFactory>
</TableColumn>
<TableColumn editable="false" prefWidth="200.0" resizable="false" sortable="false" style="-fx-font-size: 13pt;" text="Timestamp">
<cellValueFactory>
<PropertyValueFactory property="timestamp" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
И люди класса:
public class People {
public static enum Range {ONE, TWO, THREE, FOUR}
public People() {
}
private IntegerProperty id = new SimpleIntegerProperty();
public int getId() {
return id.get();
}
public IntegerProperty idProperty() {
return id;
}
public void setId(int id) {
this.id.set(id);
}
private ObjectProperty<Range> range = new SimpleObjectProperty<>();
public Range getRange() {
return range.get();
}
public ObjectProperty<Range> rangeProperty() {
return range;
}
public void setRange(Range range) {
this.range.set(range);
}
private ObjectProperty<Timestamp> timestamp = new SimpleObjectProperty<>();
public Timestamp getTimestamp() {
return timestamp.get();
}
public ObjectProperty<Timestamp> timestampProperty() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp.set(timestamp);
}
}
Моя проблема заключается в том, что когда я устанавливаю новый TimeStamp в строке people и появляется TableView, столбец не обновляет отметку времени. Я должен использовать StringProperties для автоматического обновления?
Хорошо, я получил решение.
Я обновлял временную метку таким образом:
private Timestamp actualTimestamp = new Timestamp();
private void updateTimeStamp(){
actualTimestamp.setTime(System.currentTimeMillis());
people.setTimestamp(actualTimestamp);
}
Неосвежающая причина: я не устанавливаю новый объект Timestamp, поэтому недействительность не ослабляет.
Правильный способ:
private void updateTimeStamp(){
actualTimestamp.setTime(new Timestamp(System.currentTimeMillis()));
people.setTimestamp(actualTimestamp);
}