Displaying changing values in JavaFx Label

后端 未结 4 1021
一生所求
一生所求 2020-11-30 05:10

In JavaFX, how can I display values which continuously change with time using \"label\" ?

4条回答
  •  情书的邮戳
    2020-11-30 05:40

    How about using SimpleDateFormat? There's no need for the StringUtilities class!

    private void bindToTime() {
      Timeline timeline = new Timeline(
        new KeyFrame(Duration.seconds(0),
          new EventHandler() {
            @Override public void handle(ActionEvent actionEvent) {
              Calendar time = Calendar.getInstance();
              SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
              setText(simpleDateFormat.format(time.getTime()));
            }
          }
        ),
        new KeyFrame(Duration.seconds(1))
      );
      timeline.setCycleCount(Animation.INDEFINITE);
      timeline.play();
     }
    }
    

提交回复
热议问题