package labelissue; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.paint.Color; import javafx.stage.Stage; public class LabelIssue extends Application { int clickCounter = 0; public static void main(String[] args) { Application.launch(LabelIssue.class, args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Hello World"); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN); Button btn = new Button("Click me!"); btn.setLayoutX(100); btn.setLayoutY(50); final Label lbl = new Label(""); lbl.setTranslateX(100); lbl.setTranslateY(100); btn.setOnAction(new EventHandler() { public void handle(ActionEvent event) { System.out.println("Click accepted: " + clickCounter++); if( lbl.getText().equals("") ){ lbl.setText("Hello, world!!!"); } else{ lbl.setText(""); } } }); root.getChildren().addAll(btn, lbl); primaryStage.setScene(scene); primaryStage.setVisible(true); } }