[fxruby-users] deleting children and then adding new ones

Lyle Johnson lyle at lylejohnson.name
Mon Dec 10 11:23:53 EST 2007

On 12/9/07, Ralph Douglass <ralph at grayskies.net> wrote:

> I'm trying to delete the contents of a frame (using removeChild), and then
> add new contents to that frame.  Whenever I do this, it deletes stuff just
> fine, but then the new thing doesn't show up.  Here is a short example:
> require 'fox16'
> include Fox
> app = FXApp.new()
> main = FXMainWindow.new(app, "Window")
> vf = FXVerticalFrame.new(main)
> button = FXButton.new(vf, "Old Button")
> button.connect (SEL_COMMAND) do
>   vf.removeChild(button)
>   FXButton.new(vf, "New Button")
> end
> app.create
> main.show()
> app.run
> Click the button... and then there's nothing at all.
> Is there some sort of magic incantation I need to call to get the frame to
> redraw itself or something?

Yes, you need to call create() on the button and then recalc() on the
button's parent:

	buttton.connect(SEL_COMMAND) do
		btn = FXButton.new(vf, "New Button")

Note that I'm not sure it's a good idea to destroy an object while
you're executing a message handler for it (as in this example). What
is it that you're trying to accomplish by removing the old button and
creating a new one? If you're just wanting to change the button's
label (for example), you can just do:

	button.connect(SEL_COMMAND) do
		button.text = "New Button Text"

Hope this helps,


More information about the fxruby-users mailing list