gpt4 book ai didi

java - Textarea如何在每次循环迭代后追加文本?

转载 作者:行者123 更新时间:2023-12-01 17:43:08 26 4
gpt4 key购买 nike

我想使用 TextArea 来记录有关每次迭代后发生的情况的消息。目前所有日志都附加到循环末尾。

@FXML
private TextArea logBookTextArea;

for (Input x : inputList) {

logBookTextArea.appendText("Czytam " +i+" produkt");
id = dataDownloader.downloadID(x.getProducer_code());
writer.print(x.getProduct_code() + ';');
writer.print("0;");
writer.print(producentChoiceBox.getSelectionModel().getSelectedItem().toString().toUpperCase() + ";");
writer.print(x.getProducer_code() + ";");
writer.print(x.getName() + ";");
writer.print("Import - bez kategorii;");
writer.print("4.6;");
writer.print("20;");
writeImages(id);
logBookTextArea.appendText("OK");
logBookTextArea.appendText("\n");
i++;
}

最佳答案

我假设您想要创建类似“异步调用”的内容,因为您希望在每次完成检索列表对象的值时追加数据。

你能做什么。正在围绕循环启动一个线程并将 UI 更改放入 Platform.runLater(...)

ExecutorService ex = Executors.newSingleThreadExecutor(r ->{
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
});

ex.execute(()-> {
int i = 0;
for (Input x : inputList) {
int index= i;

//must be declareid here because of lambda rules
//or put in a container that is effectively final
Int id = dataDownloader.downloadID(x.getProducer_code());
writer.print(x.getProduct_code() + ';');
writer.print("0;");
writer.print(producentChoiceBox.getSelectionModel().getSelectedItem().toString().toUpperCase() + ";");
writer.print(x.getProducer_code() + ";");
writer.print(x.getName() + ";");
writer.print("Import - bez kategorii;");
writer.print("4.6;");
writer.print("20;");
writeImages(id);
Platform.runLater(()->{
logBookTextArea.appendText("Czytam " +index+" );
logBookTextArea.appendText("OK");
logBookTextArea.appendText("\n");

});
I++
}
});

关于java - Textarea如何在每次循环迭代后追加文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58554630/

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