why this not work? : recursive panels

Hi all, i don’t understand where is the problem:


                        Panel p1 = new Panel(); p1.addComponent(new Label("panel1"));
			Panel p2 = new Panel(); p2.addComponent(new Label("panel2"));
			Panel p3 = new Panel(); p3.addComponent(new Label("panel3"));
			
			p1.addComponent(p2);
			p2.addComponent(p3); 
			
			mainWindow.addComponent(p1);
			
			p3 = new Panel();  p3.addComponent(new Label("panel4"));			
			

result → label panel4 is not showing. Shows panel3.

I tried requestRepaint() and requestRepaintAll() , replaceComponent and final p3.removeallComponents() without results too.


I need to change dinamically p3 content

??

Juan Manuel

You are not adding panel 4 to your application

Replace lines

p3 = new Panel();
p3.addComponent(new Label("panel4"));

with

Panel p4 = new Panel();
p4.addComponent(new Label("panel4"));
p3.addComponent(p4);

And it shows panels 1, 2, 3 and 4.

-Henri

Thanks Henri,

the problem is that my application needs to replace the content of the variable p3 ( defined inside a class ). So i need to replace the content of the panel p3. and show the new content.

Some idea? i need to show the new content of p3

You can replace p3 content with p3.setContent(newContent) method. There should be no need to manually call requestRepaint() or any other refreshing methods.

But if the p3 is not added into the main window (or any other visible window) or it is not in any layout that is added to the main window; it is not visible. This seem to be the problem with your code. But, if you add the panel p3 into the main window then it should be visible and replacing it’s content should be also seen in the ui.

The problem with code line 11 is that old reference to p3 is lost. If you want replace old p3 with new one you should first save it some other reference (e.g. Panel ptemp = p3;) before line 11. After that you use p2.replaceComponent(ptemp,p3); call.
addComponent(p2);

            
11            p3 = new Panel();  p3.addComponent(new Label("panel4"));  

It works!,

thank you very much Johannes

:wink:

Juan Manuel