Smalltalk, displaying OrderedCollection to List Widget

1k views Asked by At

Hi I have an ordered collection of strings which I'm trying to display on a list widget. I do the following:

self displayWidget list: coll.

where displayWidget is a List Widget and coll is the OrderedCollection containing the strings. It will display it, but it displays it in a single line.

Instead of getting

line one
line two
line three

I get:

line oneline twoline three 

I'm using visual works.*

2

There are 2 answers

0
z-index On

You can iterate the collection and send withCRs message to the Strings.

Here is an simple example:

| i |

i:= 0. [i < 5] whileTrue: [ Transcript show: 'Hello world.\' withCRs. i := i +1.

]

withCRs method replace each \ ocurrence for a new line and carry return.

Hope it helps you.

0
Greg Leaver On

Inside list: you probably want something similar to

coll do: [:element | Transcript show element; cr]

When you send do: [:e | ...] to a collection it evaluates the block once for each element in the collection, each time passing the element into element.
Each time I'm sending cr to Transcript to add a carriage return after each element.