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

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



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


      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();
              TextField field = new TextField();
              hbox.getChildren().addAll(numberSlider, field);
              hbox.setPadding(new Insets(12));

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

          public static void main(String[] args) {


          Issue Links



              leifs Leif Samuelsson (Inactive)
              rbair Richard Bair (Inactive)
              0 Vote for this issue
              0 Start watching this issue