gpt4 book ai didi

TableView 中的 Java8 ObjectProperty 不刷新

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:09 24 4
gpt4 key购买 nike

我有这个人物 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);
}
}

我的问题是,当我在人员行中设置新的时间戳并且显示 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);
}

关于TableView 中的 Java8 ObjectProperty 不刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24641295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com