Skip to content

Instantly share code, notes, and snippets.

@kevinrushforth
Last active June 22, 2023 11:46
Show Gist options
  • Save kevinrushforth/17c63d854f817d9efa176ec6090c85bc to your computer and use it in GitHub Desktop.
Save kevinrushforth/17c63d854f817d9efa176ec6090c85bc to your computer and use it in GitHub Desktop.

Summary

Provide the ability for scrollable controls to use the preferred width or height of their content as their preferred size, completely disabling horizontal or vertical scrolling. The set of controls being targeted are: ScrollPane, TextField, and WebView.

Goals

  • Enable laying out multiple controls next to each other, possibly in an enclosing ScrollPane, without each of the controls having a separate scrollbar
  • Provide separate control for horizontal and vertical scrolling
  • Preserve the current default behavior of being able to scroll both vertically and horizontally in scrollable controls

Non-Goals

  • It is not a goal to provide this capablity for classes that use VirtualFlow to virtualize rows vertically, such as TableView, TreeTableView, or ListView. A future enhancement could address those controls.

Motivation

A scrollable control, such as ScrollPane, TextField, or WebView has a size that is distinct from the size of its content. If the size of the scrollable control is smaller than the size of its content, scrollbars are added to allow the portion of the content that is shown to be scrolled. If you embed one or more scrollable controls within an outer ScrollPane, each of them will have their own scrollable region and scroll bars. The preferred size of a scrollable control, which is used when that control is laid out in a parent container, is a fixed size that is not based on the size of its content. This makes it infeasible to support an application that wants to include scrollable components within an outer ScrollPane, and lay them out in a seamless manner with each control being sized to the size of its content.

Description

We propose to add two new writable boolean properties to three classes.

Modified classes:

ScrollPane
TextArea
WebView

Properties added to the above classes:

BooleanProperty useContentWidth;
BooleanProperty useContentHeight;

If useContentWidth is true, the width of the scrollable control is the width of the content; the content of the control is not horizontally scrollable. A horizontal scrollbar will never be shown regardless of the width of the content. If useContentWidth is false, the width of the scrollable control will be independent of the width of the content; the content of the control is horizontally scrollable. A horizontal scrollbar may be used to enable scrolling, depending on other properties. The default value is false.

If useContentHeight is true, the height of the scrollable control is the height of the content; the content of the control is not vertically scrollable. A vertical scrollbar will never be shown regardless of the height of the content. If useContentHeight is false, the height of the scrollable control will be independent of the height of the content; the content of the control is vertically scrollable. A vertical scrollbar may be used to enable scrolling, depending on other properties. The default value is false.

Several properties that control scrolling in ScrollPane are ignored when useContentWidth or useContentHeight is true. For example:

  • fitToWidth, fitToHeight
  • hbarPolicy, vbarPolicy
  • hmin, hmax, vmin, vmax
  • hvalue, vvalue
  • viewportBounds (x values are ignored if useContentWidth and y values are ignored if useContentHeight)
  • minViewportWidth, minViewportHeight
  • prefViewportWidth, prefViewportHeight
  • pannanble (for the associated direction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment