我有一个带有 JafavaFx 的表格视图,用于每秒显示给用户货币。一切正常,但是当 tableView 尝试重新加载数据时,它会在几毫秒内停止,我的意思是冷冻机,看起来不太漂亮。我无法删除此行为,此时我使用的代码是:
setCache(true);
setItems(getObservableList());
Timeline animation = new Timeline();
animation.getKeyFrames().add(new KeyFrame(Duration.seconds(1), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
setItems(getObservableList());
}
}));
animation.setCycleCount(Animation.INDEFINITE);
animation.play();
我的表列
getColumns().addAll(
getStringField("id","Tikect"),
getStringField("currency","Symbol"),
getStringField("type","S/B"),
getDoubleField("amount","Amt (k)"),
getDoubleField("open","Open"),
getDoubleField("close","Close"),
getDoubleField("stop","Stop"),
getDoubleField("limit","Limit"),
getDoubleField("pl","P/L"),
getDoubleField("gpl","Gross P/L")
);
在添加列的其他类中,我有一个这样的功能:
public static TableColumn<BaseModel, String> getStringField(String idColumn,String nameColumn) {
TableColumn<BaseModel, String> column = new TableColumn<BaseModel, String>(idColumn);
column.setCellValueFactory(new PropertyValueFactory<BaseModel, String>(idColumn));
column.setMinWidth(100);
column.setText(nameColumn);
return column;
}
我的 ObservableList 是:
public ObservableList<BaseModel> getObservableList() throws IOException {
ObservableList<BaseModel> oTransacctions = FXCollections.observableArrayList();
JsonFactory factory = new JsonFactory();
JsonParser jp = factory.createJsonParser(new URL(getURL()));
JsonToken token = jp.nextToken();
while (token != JsonToken.START_ARRAY) {
token = jp.nextToken();
}
while (token != JsonToken.END_ARRAY) {
token = jp.nextToken();
if (token == JsonToken.START_OBJECT) {
Transaction transaction = parseTransacction(jp);
oTransacctions.add(transaction);
}
}
return oTransacctions;
}
private Transaction parseTransacction(JsonParser jp) throws IOException {
Transaction transaction = new Transaction();
JsonToken token = jp.nextToken();
while (token != JsonToken.END_OBJECT) {
if (token == JsonToken.START_OBJECT) {
while (token != JsonToken.END_OBJECT) {
token = jp.nextToken();
}
}
if (token == JsonToken.FIELD_NAME) {
String fieldname = jp.getCurrentName();
if ("id".equals(fieldname)) {
jp.nextToken();
transaction.setId(jp.getText());
}
if ("currency".equals(fieldname)) {
jp.nextToken();
transaction.setCurrency(jp.getText());
}
if ("type".equals(fieldname)) {
jp.nextToken();
transaction.setType(jp.getText());
}
if ("amount".equals(fieldname)) {
jp.nextToken();
transaction.setAmount(jp.getValueAsDouble());
}
if ("open".equals(fieldname)) {
jp.nextToken();
transaction.setOpen(jp.getValueAsDouble());
}
if ("stop".equals(fieldname)) {
jp.nextToken();
transaction.setStop(jp.getValueAsDouble());
}
if ("limit".equals(fieldname)) {
jp.nextToken();
transaction.setLimit(jp.getValueAsDouble());
}
if ("created_at".equals(fieldname)) {
jp.nextToken();
// transaction.setCreated_at(new Date(jp.getText()));
}
if ("pl".equals(fieldname)) {
jp.nextToken();
transaction.setPl(jp.getValueAsDouble());
}
if ("gpl".equals(fieldname)) {
jp.nextToken();
transaction.setGpl(jp.getValueAsDouble());
}
if ("close".equals(fieldname)) {
jp.nextToken();
transaction.setClose(jp.getDoubleValue());
}
}
token = jp.nextToken();
}
return transaction;
}
这是结果:
我的问题是:
- 我应该使用网格等其他组件,...来做这种类型的动作吗?
- 如果可能的话我应该怎么做?
非常感谢 !