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

TextFieldSkin.computePrefWidth not working properly with monospaced font

    Details

    • Subcomponent:
    • Introduced In Build:
      b17
    • Introduced In Version:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Mac OS X El Capitan / jdk-11-ea+13 x64

      A DESCRIPTION OF THE PROBLEM :
      If ColumnPrefProperty is bound to the length of the TextProperty, problems occur when a monospaced font is used. The text is placed outside of the view and only becomes visible after double-clicking the TextField or moving the cursor to the left.


      ---------- BEGIN SOURCE ----------
      This is a minimal example that reproduces this behavior.

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception{
              Stage stage = new Stage();
      final TextField a = new TextField();
      a.prefColumnCountProperty().bind(a.textProperty().length());
      a.setStyle("-fx-font-family: 'monospaced';");
              VBox box = new VBox(0);
              box.setMinWidth(0);
              box.setFillWidth(false);
              box.getChildren().addAll(a);
              stage.setScene(new Scene(box, 200, 200));
              stage.show();
          }


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

      CUSTOMER SUBMITTED WORKAROUND :
      A simple fix is to use a.prefColumnCountProperty().bind(a.textProperty().length().add(1)) instead of a.prefColumnCountProperty().bind(a.textProperty().length());.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: