Galera, I've been struggling for some months because of not getting a label
to keep updating constantly.
I can do a timer, but when it comes to the interface created by scene builder , it hangs because I could not update the label
, I think.
Please help me, I'm in great need.
Example:
package progrma.de.teste.nivel.pkg2;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
public class interface2 implements Initializable {
@FXML
private Label label;
private int contador=0;
@FXML
private void handleButtonAction(ActionEvent event) {
Timer tm = new Timer();
tm.scheduleAtFixedRate(new TimerTask(){
@Override
public void run() {
contador++;
int seg = contador %60;
int min = contador /60;
int hora = min /60;
min %= 60;
label.setText(String.format("%02d:%02d:%02d:",hora,min,seg));
}
},1000,1000);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}