The issue is with how GUIDE is setting the Parent
property of your second UIpanel. As you're dragging panel 2 onto panel 1, if panel 1 is highlighted it will be set as the parent of panel 2. The visibility of the children in a panel is controlled by their parent panel, so when you turn panel 1's visibility off it also turns off panel 2 if it's a child.
Here are two ways to fix this:
- When dragging in GUIDE, overlap them so that panel 1 is not highlighted and release. You can start dragging the panel 2 again and should be able to bring it further on top of panel 1. This method works but to me seems really annoying
Add something along the lines of the following to your 'OpeningFcn'
set(handles.uipanel2,'Parent',handles.figure1,'Position',get(handles.uipanel1,'Position'));
As an artifact of setting the parent of panel 2 to panel 1, the
Position
property of panel 2 is relative to panel 1, so you have to just copy the position vector from panel 1 to panel 2.
Alternatively you can look into generating your GUIs programmatically and not having to deal with GUIDE and these weird little issues.