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

TextField text alignment fails when delayed setText() call with alignment = Pos.CENTER

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Labels:
    • Environment:

      Javafx JDK 2.1 b14, Java SE 7u3 JRE i586
      Ubuntu 11.10 x64

      Description

      Maybe only a linux related bug, try this and you should see that instead of being centered, the text starts at the center of the TextField.
      I don't know if Platform.runLater() is mandatory for setText but it doesn't change anything to use it or not.

      package test;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class Test extends Application {

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

      @Override
      public void start(Stage stage) throws Exception {
      BorderPane bp = new BorderPane();
      final TextField tf = new TextField();
      tf.setAlignment(Pos.CENTER);
      tf.setPrefColumnCount(20);
      tf.setMaxHeight(20);
      tf.setMaxWidth(200);
      bp.setCenter(tf);
      Scene scene = new Scene(bp, 300, 300);
      stage.setScene(scene);
      stage.show();
      new Thread(new Runnable() {

      @Override
      public void run() {
      try {
      Thread.sleep(3000);
      } catch (InterruptedException e) {
      }
      // tf.setText("try to center this !"); -- same behavior as with
      // Platform.runLater()
      Platform.runLater(new Runnable() {

      @Override
      public void run() {
      tf.setText("try to center this !");
      }

      });
      }
      }).start();
      }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              leifs Leif Samuelsson (Inactive)
              Reporter:
              pmarsonjfx Pitt Marson (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: