Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
AlignmentMorph newColumn and TextMorphs example
Last updated at 4:14 pm UTC on 6 October 2018
 | column box1 headingText box2 box3 |
 column := AlignmentMorph newColumn cellPositioning: #topLeft.


 headingText := 'This is the heading' asText allBold.
 box1 := TextMorph new leftFlush; contents: headingText.
 box1 backgroundColor: Color white.
 column addMorphBack: box1.


 box2 := TextMorph new leftFlush; contents: 'paragraph of box 2'.
 box2 backgroundColor: Color lightBlue.
 column addMorphBack: box2.


 box3 := TextMorph new leftFlush; contents: 'paragraph text of box3'.
 box3 backgroundColor: Color lightGray.
 column addMorphBack: box3.

 column openInHand

AlignmentMorphWith3boxes.png

Note that with the code above the extent of the object called column is not properly set.

To see this evaluate
 column extent 
The result is
 1@1

To fix this it needs at the beginning

  column  hResizing: #shrinkWrap.
  column  vResizing: #shrinkWrap.

The whole script again

 | column box1 headingText box2 box3 |
 column := AlignmentMorph newColumn cellPositioning: #topLeft.
 column  hResizing: #shrinkWrap.
 column  vResizing: #shrinkWrap.

 headingText := 'This is the heading' asText allBold.
 box1 := TextMorph new leftFlush; contents: headingText.
 box1 backgroundColor: Color white.
 column addMorphBack: box1.


 box2 := TextMorph new leftFlush; contents: 'paragraph of box 2'.
 box2 backgroundColor: Color lightBlue.
 column addMorphBack: box2.


 box3 := TextMorph new leftFlush; contents: 'paragraph text of box3'.
 box3 backgroundColor: Color lightGray.
 column addMorphBack: box3.


 column openInHand.

This code also works in Pharo 7.

See also

AlignmentMorph newColumn example with three submorphs