I have been working on a matlab GUI for a while now and have finally gotten it do what I want now I am just working on making a bit cleaner and user friendly. I have 5 panels and have stacked them all on top of each other and have added 5 push buttons on top of the panel. Is there a way to be able to bring a panel to the front by pressing on the push button? (This the easiest way I can think of to make tabs that will jump from panel to panel)
function togglebutton2_Callback(hObject, eventdata, handles)
This is my call back for the push button. Is there anything I can add to bring a panel to the front by simply clicking on the push buttton? Thanks

 Akzeptierte Antwort

Adam Danz
Adam Danz am 30 Jul. 2018
Bearbeitet: Adam Danz am 30 Jul. 2018

1 Stimme

Two options off the top of my head. Both of these options would be executed in your pushbutton callback function where you also need access to the panel handles.
Option 1: 'Visible' property
Set all panels to 'off' except for the one "on top" which will be set to 'on'.
set([p1,p2,p3,p4,p5], 'Visible', 'off')
p3.Visible = 'on';
Option 2: uistack()
Put the panel you'd like to see on top of the rest.
uistack(p3, 'top')
The better option is the first one.

5 Kommentare

Hector De La Torre
Hector De La Torre am 30 Jul. 2018
Bearbeitet: Hector De La Torre am 30 Jul. 2018
If i go with option 1 would p1, p2, p2 etc. equal the handle that corresponds to each panel?
For example if the callback for my panel is:
function uipanel1_CreateFcn(hObject, eventdata, handles)
would my handle be handles.uipanel1 ?
Also if i have 5 push buttons would I have to set all panels off within each individual pushbutton calllback function?
Thanks!
Adam Danz
Adam Danz am 30 Jul. 2018
Bearbeitet: Adam Danz am 30 Jul. 2018
If i go with option 1 would p1, p2, p2 etc. equal the handle that corresponds to each panel?
Yes.
For example if the callback for my panel is... would my handle be handles.uipanel1 ?
Yes, but I think you'd want to set the visibility from the pushbutton callback. In that case, the handles would still be handles.uipanel1, etc.
Also if i have 5 push buttons would I have to set all panels off within each individual pushbutton calllback function?
I think the easiest approach would be create a separate function with two inputs: 1) the handle to the panel you want to be active and 2) the 'handles' structure that contains all handles. In this function you'll turn off ALL panels and turn on the one you want to see.
function togglePanels(activeHandle, handles)
set([handles.uipanel1, handles.uipanel2, ..., 'handles.uipanel5], 'Visible', 'off')
set(activeHandle, 'Visible', 'on')
Then, all of your button callbacks will merely call this function.
function button1Callback(~,~,handles)
togglePanels(handles.uipanel1, handles)
Hector De La Torre
Hector De La Torre am 31 Jul. 2018
Nice I tried this method and it works but I still have a problem. When I run the script and GUI pops up all my panels are visible. How can I make it so that when I run the script only uipanle1 is up and visible? (Toggling between buttons and does exactly what I wanted to do thanks!)
Hector De La Torre
Hector De La Torre am 31 Jul. 2018
Never mind once I stack the panels on top of each other then I should only be able to see the one on top. Thanks!
Adam Danz
Adam Danz am 31 Jul. 2018
Bearbeitet: Adam Danz am 31 Jul. 2018
You need to initialize the panels with the 'Visible' 'off' property set. If you're using GUIDE, you can open the GUI in GUIDE and set the properties there. An alternative is to call the togglePanels() function from the ..._OpeningFcn().

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017b

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by