Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Recipe: Create a window with scrollable contents
Last updated at 11:04 am UTC on 15 January 2016

Example1


The following code opens a window (an instance of SystemWindow) with scroll bars (provided by ScrollPane) and a scrollable window pane. The window pane in this case is a PasteUpMorph onto which other morphs can be dropped.
window := SystemWindow new.
scrollPane := ScrollPane new.
pasteUpMorph := PasteUpMorph new.
pasteUpMorph extent: 1000@1000.
scrollPane scroller addMorph: pasteUpMorph.
window addMorph: scrollPane frame: (0@0 corner: 1@1).
window openInWorld.


You will see the following

Uploaded Image: Untitled Window.png

Notice the horizontal and vertical scrollbars. They enable you to view various parts of the paste-up-morph which is much larger than the system-window.

Appearance of scrollbars is affected by PreferencesPanel.
Uploaded Image: Preferences.png

This code works in Squeak 3.7, 3.8, 3.9a, 4.4 and 5.0. In older Squeak versions it may be possible to use TwoWayScrollPane (if present) instead of ScrollPane.

Example2

You can add easily new morphs to the scrollable area:
window := SystemWindow new.
scrollPane := ScrollPane new.
pasteUpMorph := PasteUpMorph new.
pasteUpMorph extent: 1000@1000.
scrollPane scroller addMorph: pasteUpMorph.
window addMorph: scrollPane frame: (0@0 corner: 1@1).
0 to: 1000 by: 100 do: 
	[:x | 0 to: 1000 by: 100 do:
		[:y |
			point :=  x@y.
			textMorph := TextMorph new contents: point asString.
			textMorph position: point.
			pasteUpMorph addMorph: textMorph
		]
	].
window openInWorld.

Uploaded Image: Untitled Window1.png

Example3


bookMorph := BookMorph new borderWidth: 1.
scrollPane := ScrollPane new.
scrolledMorph := Morph new
	color: Color white;
	hResizing: #shrinkWrap;
	vResizing: #shrinkWrap.
scrollPane scroller addMorph: scrolledMorph.
0 to: 1000 by: 100 do: 
	[:x | 0 to: 1000 by: 100 do:
		[:y |
			point :=  x@y.
			textMorph := TextMorph new contents: point asString.
			textMorph position: point.
			scrolledMorph addMorph: textMorph
		]
	].
bookMorph pages first
	layoutPolicy: ProportionalLayout new;
	addMorph: scrollPane
		fullFrame: (LayoutFrame fractions: (0.1 @ 0.1 corner: 0.9 @ 0.9));
	extent: 300@300.
bookMorph openInWorld.

produces something similar to
Uploaded Image: Book.png

Example4


Recipe: Create a window with scrollable contents - example 4

See Also


How to lay out submorphs — might be useful if you wanted to add ScrollPane to something different than SystemWindow.