Search code examples
scrollviewsmalltalksqueak

How to make a scrollpane adjust to its content?


I am trying to display a Morph that can grow and shrink while it is displayed. In order not to risk that the Morph grows out of it's window, I would like to put it in a ScrollPane so that it can be scrolled if it gets too large for the window. As an example:

rows := Morph new


layoutPolicy: TableLayout new;
    listDirection: #topToBottom;
    color: Color white.
sp := ScrollPane new
    extent: 100@100.
sp scroller addMorph: rows.

rows addMorphBack: (RectangleMorph new color: Color red).
rows addMorphBack: (RectangleMorph new color: Color blue).
sp openInWindow.
rows addMorphBack: (RectangleMorph new color: Color green).

My problem is that in this example the green rectangle does not fit in the window anymore, but no scrollbar is shown. If the last two lines of code are switched, I do get a scrollbar.

Therefore my question: Is there a way to let a ScrollPane know that the Morph in it's scroller has increased?


Solution

  • I was about to answer the same as aka.nice But it does not always show the right scrollbar. It seems

    sp setScrollDeltas.
    

    Does the same as hideOrShowScrollBars and a little bit more.