# How to refresh a panel?

**URL:** <https://www.ruby-forum.com/t/how-to-refresh-a-panel/153258>\
**Category:** wxRuby\
**Created:** [November 14, 2008, 1:22am UTC](https://www.ruby-forum.com/t/how-to-refresh-a-panel/153258 "2008-11-14T01:22:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@ramo](https://www.ruby-forum.com/u/ramo)\
**Post date:** [November 14, 2008, 1:22am UTC](https://www.ruby-forum.com/t/how-to-refresh-a-panel/153258/1 "2008-11-14T01:22:43Z")

</div>

Hello again

This time i have a problem with this code

Well, what i’m trying to do is, through a menu, to change panels.  
The problem is that i can’t find a way to change the panel, or refresh  
or delete, or whatever should be done.

i’ve attached the the zip file with the runable code

the code is:  
##on ‘def initialize’ of a Wx::Frame class  
#@Panel=Panel.new(self)##If i initialize @panel here, it doesn’t refresh  
when the event is called  
###end initialize

###event functions##  
def cState(menu)##the function called from the event  
#@panel.destroy ## Error: undefined method `destroy’ for  
nil:NilClass (NoMethodError)  
@panel=Test.new(self)##a WX::Panel class.  
end  
##the other function is similar to this one  
###end event functions

if i’m doing the wrong way, please tellme, and if possible, post a link  
to an example, tutorial or explanation. I’d be very thankful

Ramo

---

<div class="post-metadata">

**Author:** ![ramo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@ramo](https://www.ruby-forum.com/u/ramo)\
**Post date:** [November 14, 2008, 1:58am UTC](https://www.ruby-forum.com/t/how-to-refresh-a-panel/153258/2 "2008-11-14T01:58:22Z")

</div>

Omar H. wrote:

> Well, what i’m trying to do is, through a menu, to change panels.  
> The problem is that i can’t find a way to change the panel, or refresh  
> or delete, or whatever should be done.

First off, have a look at whether a Wx::Notebook might suit your  
requirements. It’s intended for combining different panels. It has  
methods for switching easily between pages.

If you want to swap panels, you probably just need to destroy the old  
panel and add in the new (see below)

I’m more used to doing this within a sizer-based layout, when it goes  
something like:

new\_window = MyWindow.new(old\_window.parent, …)  
old\_window.containing\_sizer.replace(old\_window, new\_window)  
old\_window.destroy

This keeps the layout consistent

> i’ve attached the the zip file with the runable code
> 
> the code is:  
> ##on ‘def initialize’ of a Wx::Frame class  
> #@Panel=Panel.new(self)##If i initialize @panel here, it doesn’t refresh

Well one problem you have is that you call it @Panel here (with a  
capital “P”) and @panel later.

alex
