2 回答
TA贡献1836条经验 获得超3个赞
将您的 handleMouseClickMethod 更改为如下所示,它应该可以工作
public void handleMouseClick(){
int delayTime = 10;//Set this to whatever you want your delay in Seconds
Label text = new Label("please wait");
mainPane.getChildren().add(text);
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(()->
Platform.runLater(()->mainPane.getChildren().remove(text)), delayTime, 1, TimeUnit.SECONDS);
}
TA贡献1794条经验 获得超8个赞
编辑:
由于 kleopatra 指出旧代码段不起作用,我已经搜索了如何做到这一点并找到了这个答案:
“以下代码将暂停并更改标签中的值(完全公开,我正在重用我为另一个问题编写的代码):”
https://stackoverflow.com/a/26454506/10971694
老的:
下面的代码会有帮助吗?
while(!node.isVisible()){
System.out.println("waiting...");
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
添加回答
举报
