FAQ: Entry Field in Morphic
Last updated at 11:06 am UTC on 15 March 2003
How can I generate an entry field in Morphic?
If you want to use TextMorph, two very useful methods are
- #contentsWrapped:
- #extent:.
The example below creates a fixed-width entry field in a morphic world:
tm _ TextMorph new.
tm contentsWrapped: ''; extent: 100@20. "this is the important stuff"
(border _ AlignmentMorph newRow) "this just makes the TextMorph easier =to see"
position: 200@200;
borderWidth: 1;
borderColor: Color black;
hResizing: #shrinkWrap;
vResizing: #shrinkWrap;
addMorph: tm.
World addMorph: border.
Further decisions to make include:
- Whether and how to limit the characters entered. You may want to create a subclass of TextMorph that provides additional behavior that many data-entry applications require (max characters, specific characters, formatting, etc).
- What do do if the number of characters entered exceeds the allotted space. The TextMorph in the example above simply expands to add more rows of characters. If this is not desirable, you may want to look instead at PluggableTextMorph which adds a scrollbar.
BobArning