ScrollPane has the feature for content that needs to track the viewportBounds 
size, FitToWidth/FitToHeight, which is nice for things like text areas that 
wrap text. Conceptually, it seems like FitToWidth is basically binding 
Content.PrefWidth to ViewportBounds.Width.

But it seems more often I really want to bind Content.MinWidth/MinHeight to 
ViewportBounds.Width/Height. This is common for things like text areas that 
don't wrap text or most text area height (and much more). So I end up doing a 
bit of this:

    // Add content to ScrollPane and make sure it is at least as big as 
    final Region content = myContent;
    ScrollPane scrollPane = new ScrollPane(); scrollPane.setContent(content);
ChangeListener<Bounds>() {
        public void changed(ObservableValue<? extends Bounds> arg0, Bounds 
oldBounds, Bounds newBounds)
        { content.setMinWidth(newBounds.getWidth()); 
content.setMinHeight(newBounds.getHeight()); }});

To me, this makes it seem like the ScrollPane is only there when it's needed 
(otherwise, it's like an invisible Parent Pane). This seems ideal for a default 

Obviously, this isn't a lot of code, but it's non-obvious, and from googling, 
it looks like people stumble over FitToWidth first. It seems to me that a 
setGrowToFitWidth/setGrowToFitHeight would be at least as useful. Unless I 
missed something. :-)

Jeff Martin

Reply via email to