How to actively change a label's string in visualworks smalltalk
I am trying to dynamically change the value of a label in an ApplicationModel dynamically during the running of my p开发者_如何转开发rogram. I have tried:
(self builder labelAt: #Label4) labelString: 'Dynamic text here'.
But get a labelString not understood error. When I run:
(self builder labelAt:#Label4)
I get "UndefinedObject". Which obviously suggests that I am not returning my Label object.
Try
(self builder componentAt: #Label4) widget labelString: 'whatever'
or
(self widgetAt: #Label4) labelString: 'whatever'
If you have a Model for your changing value it's pretty easy to use read-only InputField bound to your model. I dare to say having a Model for a changing value is generally a good idea.
If you define InputField as read-only and withou a border, it will look exactly like a regular text label. From a user's point of view the only difference is in ability to select and copy text from read-only input field, which is useful in many cases.
On the other hand, Labels can have a much richer look. You can use Text, ComposedText or Image for them.
精彩评论