Questions about smalltalk/x and its class library

redisplay problem

Postby duetto » 2. Feb 2010, 16:26

hi all,

i'm building a test application. the goal is to be able to add and remove widgets dynamically. the test application has a VerticalPaneView and 2 Buttons. clicking the buttons add labels to the paneview. i have implemented postBuildWith: and an action method for each button. i add the first label in postBuildWith:. when the application opens the initial label is displayed.

the problem is that on clicking the buttons the displayed label text doesn't change. i have inspected the subpane and the new label is in its subviews collection. i have tried sending the invalidate and redraw messages to the label and subpane with no results. what am i missing?

below are the postBuildWith: and button action methods. currentWidget and panelView are instance vars.


postBuildWith: aBuilder


|widget|

panelView := aBuilder componentAt: #ID222.

widget := Label new.
widget name: 'GenericLbl'.
widget label: 'START'.
panelView add: widget.
currentWidget := widget.
self halt.


buttonActionMethod1
<resource: #uiCallback>

|widget|

panelView removeComponent: currentWidget.
self halt. ****************** panelView subViews collection is empty
widget := Label new.
widget name: 'GenericLbl'.
widget label: 'FUEL'.
currentWidget := widget.
panelView add: widget. ****************** panelView subViews collection is has new label
panelView invalidate.
duetto
 
Posts: 22
Joined: 28. Sep 2009, 02:43

Re: redisplay problem

Postby jan_vrany » 10. Feb 2010, 09:22

Here is the code that Michael Beyl sent me couple of years ago. It dynamically
adds/removes a button to/from a panel. Hope this snippet will help.

Code: Select all
    |top p v1 v2 b|

         top := StandardSystemView new.
         top extent:300@300.

         b := Toggle label:'show' in:top.
         b showLamp:false.
         b origin:0.0 @ 0.0 corner:(1.0 @ 40).
         b action:[:state |
                 state ifTrue:[
                     b label:'hide'.
                     v1 origin:0.0 @ 0.0 corner:1.0 @ 0.5.
                     v2 := ScrollableView for:Button.
                     v2 origin:0.0 @ 0.5 corner:1.0 @ 1.0.
                     v2 labelString:'another button'.
                     p addSubView:v2.
                 ] ifFalse:[
                     b label:'show'.
                     v2 destroy.
                     v1 origin:0.0 @ 0.0 corner:1.0 @ 1.0
                 ]
             ].

         p := VariableVerticalPanel
                 origin:0.0 @ 0.0
                 corner:1.0 @ 1.0
                 in:top.
         p topInset:50.

         v1 := ScrollableView for:EditTextView in:p.
         v1 origin:0.0 @ 0.0 corner:1.0 @ 1.0.
         v1 contents:'some text'.

         top open
jan_vrany
 
Posts: 28
Joined: 10. Dec 2008, 12:37


Return to Programming Help

Users browsing this forum: No registered users and 1 guest

Design by GB