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

Text is not centered in the textfield if the text is set programatically

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • fx2.1
    • javafx
    • JavaFX 2.1 build b17, WindowXp

      https://forums.oracle.com/forums/message.jspa?messageID=10219772

      If you set the text in the constructor, the center of the text is in the center of the control.
      But if you set the text programmatically (and the text was previously empty), then then the left side of the text is in the center of the control.

      final TextField tf = new TextField();
      Button btn = new Button("update");
      btn.setOnAction(new EventHandler<ActionEvent>(){

      @Override
      public void handle(ActionEvent t) {
      tf.setText("Hello");
      }
      });
      tf.setAlignment(Pos.CENTER);
      tf.setMinSize(200, 24);
      tf.setMaxSize(200, 40);
      tf.setPrefSize(200, 40);
      tf.setStyle("-fx-font: 20 arial;");

            leifs Leif Samuelsson (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: