I have come up with the following solution: add an event listener - every-time an element is added, removed or replaced resize the ListView's height. When resizing check wether you have only a vertical and/or horizontal scroll-bar. If only a vertical scroll-bar exists use its height and insets to get the cell height. If a horizontal scroll-bar also exists add its height too (height of the thumb). Here are the relevant code snippet (in Scala):
def extendHeight(thumbnails: ListView[String], vertical: Option[ScrollBar], horizontal: Option[ScrollBar]): Unit = {
(vertical, horizontal) match {
case (None, None) => ()
case (None, Some(_)) => ()
case (Some(v), None) =>
resizeHeight(thumbnails, v, 0)
case (Some(v), Some(h)) =>
val extra = if (h.isVisible) h.getHeight else 0
resizeHeight(thumbnails, v, extra)
}
}
def resizeToFrame(thumbnails: ListView[String]): Unit = {
val (vertical, horizontal) = PStoryBoardUX.getScrollBars(thumbnails)
PStoryBoardUX.extendHeight(thumbnails, vertical, horizontal)
}
thumbnails.getItems.addListener( new ListChangeListener[String] {
override def onChanged(c: Change[_ <: String]): Unit = {
javafx.application.Platform.runLater( () => {
// At thus point in time the scrollbars have not been updated
// So we don't know if they will be active or not. Force this
thumbnails.layout()
// Now resize to remove the visible scrollbars
resizeToFrame(thumbnails)
})
}
})