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

TextArea cannot shrink to a single row without horizontal scrollbar

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u40
    • javafx
    • Observed on Windows 8.1 x64

      TextArea allows requesting the height of a single text row via setPrefRowCount(1). This results in correct display when the TextArea's horizontal scrollbar is visible.

      However, when the horizontal scrollbar is hidden by setWrapText(true), the height of the TextArea remains the same as if the scrollbar were still present. That height amounts to nearly two rows of text rather than one, contradicting the requested setPrefRowCount.

      Paste the following sample code into the start method of an empty JavaFX project:

              final String word = "abcdefghijklmnopqrstuvwxyz";
              final String content = String.join(" ", word, word, word, word, word, word);
              
              TextArea[] areas = new TextArea[2];
              for (int i = 0; i < areas.length; i++) {
                  areas[i] = new TextArea(content);
                  areas[i].setWrapText(i == 0);
                  areas[i].setPrefRowCount(1);
              }
              
              VBox root = new VBox();
              root.getChildren().addAll(areas);

              Scene scene = new Scene(root, 300, 250);
              
              primaryStage.setTitle("JavaFX Text Test");
              primaryStage.setScene(scene);
              primaryStage.show();

      Observe that both TextAreas are exactly the same height, resulting in the first TextArea showing nearly two rows of text, even though only one row was requested. TextArea should (at least on initial display) check whether a horizontal scrollbar will be shown, and reduce its height accordingly if not.

            Unassigned Unassigned
            cnahrjfx Christoph Nahr (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported: