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();
}
}
添加回答
舉報