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

ScrollPane: horizontal scrollBar hides content


    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9, 10
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:


      This happens (only) if hbarPolicy is AS_NEEDED. To reproduce, run the example below

      - the initial hPolicy is always, hBar showing and content fully visible (note the "g" completely visible)
      - press button to toggle hBar to AS_NEEDED: hbar is hidden, height of scrollPane adjusted
      - decrease width of window such the hBar is visible again
      - expected: height of scrollPane adjusted such that its content is fully visible
      - actual: height of scrollPane not adjusted, hBar is placed above content (note the "g" not completely visible)

      Problem seems to be in ScrollPaneSkin.computePrefHeight which doesn't take the height of the hBar into account (see https://stackoverflow.com/a/49390093/203657 for a workaround). Probably similar for computePrefWidth, didn't check, though.

      The example:

       * horizontal scrollbar hides content
       * https://stackoverflow.com/q/49386416/203657
       * @author Jeanette Winzenburg, Berlin
      public class ScrollPaneSizingBug extends Application{

          private Parent createContent() {
              Text bigFatText = new Text("something");
              // increase size to get out of minHeight
              ScrollPane scroll = new ScrollPane(bigFatText);
              // no vbar to not interfere
              // start with correct height
              Button policy = new Button("toggle HBarPolicy");
              policy.setOnAction(e -> {
                  ScrollBarPolicy p = scroll.getHbarPolicy();
                  scroll.setHbarPolicy(p == ALWAYS ? AS_NEEDED : ALWAYS);
              Button measure = new Button("measure");
              measure.setOnAction(e -> {
                  Node content = bigFatText;
                  ScrollBar bar = ((ScrollPaneSkin) scroll.getSkin()).getHorizontalScrollBar();
                  LOG.info("hbar visible? parent/scroll: " + bar.isVisible() + " / "
                          + content.prefHeight(-1) + " / " + scroll.prefHeight(-1));
              Label policyText = new Label();
              HBox buttons = new HBox(10, measure, policy, policyText);
              BorderPane content = new BorderPane();
              return content;

          public void start(Stage stage) throws Exception {
              stage.setScene(new Scene(createContent()));

          public static void main(String[] args) {

          private static final Logger LOG = Logger





            • Assignee:
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: