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

Right aligned text fields don't reposition text correctly when text is programatically updated

    Details

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

      Description

      Here is a simple reproducible test case. Run the app and adjust the slider. You will see that the text in the text field is not repositioned such that it remains properly right aligned. This appears to be due to the TextFieldSkin not even being notified of the change in the text. I suspect if, after changing the text, the caret position were repositioned to the end of the text, alignment would work correctly (since TextFieldSkin does pay attention to the caret position). What I am not certain of is what the correct behavior for the caretPosition should be. In a right aligned text field, should the caret always be reset to the very last position when the text is changed manually??

      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Slider;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      /**
       * The TextFieldSkin has a bug for right or I would imagine center aligned text.
       * If you alter the text on the text field in code, the text in the text field
       * is updated but not repositioned. I'm not sure why this works as is for left
       * aligned text, but perhaps it is due to the caret position not changing
       * in the left aligned case whereas in the right aligned case, the caret
       * position is adjusted.
       */
      public class RightAlignedTextNotPositionedCorrectlyApp extends Application {
          @Override public void start(Stage stage) throws Exception {
              HBox hbox = new HBox(7);
              Slider numberSlider = new Slider();
              numberSlider.setMin(0);
              numberSlider.setMax(1000000);
              TextField field = new TextField();
              field.setAlignment(Pos.BASELINE_RIGHT);
              field.textProperty().bind(numberSlider.valueProperty().asString());
              hbox.getChildren().addAll(numberSlider, field);
              hbox.setPadding(new Insets(12));
              hbox.setAlignment(Pos.CENTER);
              hbox.setFillHeight(false);

              stage.setScene(new Scene(hbox, 640, 480));
              stage.show();
          }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                leifs Leif Samuelsson (Inactive)
                Reporter:
                rbair Richard Bair
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: