Java: Timer (wait x seconds)
java, timer
Solution
Create a TimerTask which is started after 3 seconds. This TimerTask has to execute the code which uses gui components via Platform.runLater(new Runnable())
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
label.setText("");
}
});
}
}, 3000);
Problem
I have a simple GUI that can save and get some data out of an .doc file. When i press a save button, i have a label that says "Succes" or "Error" via label.setText(); Update: The code is meant to be ran in a FXMLDocumentController (built på SceneBuilder) I want the label to go back to being empty ("") after 3 seconds.. I have tried: ``` try { Thread.sleep(1000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); ``` } but is it like, that the sleep-function freezes the whole GUI so i can't interact with it while it's sleeping. How do i set up an timer that does not affect usability? :)