1

I am a beginner Java programmer and have a question and really appreciate if you can help me. I use Netbeans and in default JavaFX fxml Application, there is a button that prints "Hello world" when it is pressed.

    @FXML
    private void handleButtonAction(ActionEvent event) {
        System.out.println("You clicked me!");
        label.setText("Hello World!");
    }

Is there a way to change the color of button (using button.setStyle() ), exactly 5 seconds after it is first pressed? Meantime, I want the button remains functional during that 5 seconds and prints "Hello world" when it is pressed.

I tried use sleep() function but then the button would not be functional during that period. Is there is an alternative way to code this?

  • 4
    I don't do JavaFX but it looks like using a [Timeline](https://docs.oracle.com/javase/8/javafx/api/javafx/animation/Timeline.html) might be the 'proper' way to do it – g00se Nov 25 '22 at 13:35
  • 4
    Use a `PauseTransition` and change the color in the `onFinished` handler. – James_D Nov 25 '22 at 13:50

0 Answers0