Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8123364

Font property is not set from another thread by platform#runLater

    XMLWordPrintable

Details

    Description

      To reproduce:
      1. Click the button 'set font'
      Result: font won't change
      Expected: font should increase

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.PasswordField;
      import javafx.scene.control.TextArea;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Font;
      import javafx.stage.Stage;

      public class TextFieldApp extends Application {

          public static void main(String[] args) {
              launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {
              stage.setScene(createScene());
              stage.show();
          }

          private Scene createScene() {

              final TextField textField = new TextField("2/2/2000");
              final PasswordField passwordField = new PasswordField();
              final TextArea textArea = new TextArea("Test");

              Button setFont = new Button("Set font");
              setFont.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      new Thread(new Runnable() {
                          @Override
                          public void run() {
                              Platform.runLater(new Runnable() {
                                  @Override
                                  public void run() {
                                      textField.setFont(new Font(20));
                                      passwordField.setFont(new Font(20));
                                      textArea.setFont(new Font(20));
                                  }
                              });
                          }
                      });
                  }
              });

              VBox root = new VBox(5);
              root.getChildren().addAll(textField, passwordField, textArea, setFont);

              return new Scene(root, 1200, 800);
          }
      }

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: