# Sizers + StaticText

**URL:** <https://www.ruby-forum.com/t/sizers-statictext/223124>\
**Category:** wxRuby\
**Created:** [September 22, 2012, 5:39pm UTC](https://www.ruby-forum.com/t/sizers-statictext/223124 "2012-09-22T17:39:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 22, 2012, 5:39pm UTC](https://www.ruby-forum.com/t/sizers-statictext/223124/1 "2012-09-22T17:39:55Z")

</div>

I’ve got some Problems with sizers and StaticTexts.

My Code:

@sizer = VBoxSizer.new  
@sizer.add\_item(StaticText.new(self, -1, “Test”), flag: ALIGN\_CENTRE)

Until here, everything is OK, Text appears on screen at the right place.

Now i want to remove this Text and replace it with two others. For this  
do the following:

@sizer.remove(0)  
@sizer.layout()  
@sizer.add\_item(StaticText.new(self, -1, “Min”), flag: ALIGN\_CENTRE)  
@sizer.add\_item(StaticText.new(self, -1, “Max”), flag: ALIGN\_CENTRE)

Now “Min” and “Max” appear at the right place (Min at the place of  
“Test” and “Max” under it), but the old Text “Test” is still in place  
and “behind” “Min” visible.

What am i doing wrong? Any ideas?

---

<div class="post-metadata">

**Author:** ![dasch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dasch](https://www.ruby-forum.com/u/dasch)\
**Post date:** [September 24, 2012, 12:09am UTC](https://www.ruby-forum.com/t/sizers-statictext/223124/2 "2012-09-24T00:09:11Z")

</div>

hi

On 22/09/2012 16:39, Daniel S. wrote:

> @sizer.remove(0)  
> @sizer.layout()  
> @sizer.add\_item(StaticText.new(self, -1, “Min”), flag: ALIGN\_CENTRE)  
> @sizer.add\_item(StaticText.new(self, -1, “Max”), flag: ALIGN\_CENTRE)

I haven’t tried, but - you might try calling destroy() on the StaticText  
you’re deleting. In wxRuby you don’t usually need to call this but here  
it might be appropriate:

[http://wxruby.rubyforge.org/doc/window.html#Window\_destroy](http://wxruby.rubyforge.org/doc/window.html#Window_destroy)

And usually, layout() is called after you have finished doing all  
changes to the contents of a Sizer.

alex
