This script provides a template on how to create simple tab panels within a GUI. Each tab panel should be a different panel with different components and can be easily created with GUIDE. By using GUIDE, you can create as many different panels as you want and layout them in a comfortable way for building. When the script initiates, it places them one behind the other and handles their visibilities accordingly.
The main idea behind simpletab is that you can create the tab labels by creating an equal number of static text uicontrols and layout them properly over an empty panel of proper defined size (see simpletab.fig in GUIDE). You can use then their positions to create axes objects (so that an edge line can be displayed around tabs without having to define the 'CData' property) and then create text objects (which are also more customizable than static text uicontrols) inside them. The control and highlighting of different tabs is performed through properly defined object callbacks (see code). The initial static text uicontrols are invisible in the final window. They are only used inside GUIDE for positioning purposes only.
Make sure that the panel which is used for the proper placement of the static text uicontrols is the bigger one as the others will acquire its position. Ideally, the other panels should not be designed to be very different from the first one in terms of their dimensions because normally, in a multitab window all tabs should have the same size and the desired uicontrols should be fitted into them.
Panagiotis Moulos (2021). Simple tab panel (https://www.mathworks.com/matlabcentral/fileexchange/15193-simple-tab-panel), MATLAB Central File Exchange. Retrieved .
thanks !! You are my favorite author!!
When i move the tab-buttons the first one looks odd. The text is shifted to the left beyond the buttons edge.
Although the code is very redundant, in a way I appreciate the redundancy because it makes it easy to see what's going on in this code without having to deal with extra fluff.
If elimination of redundancy is desired:
1. Utilize for loops and dynamic field names in the opening function. Example: Rather than handles.a1=..., use handles.(strcat('a',eye))=..., where eye is the for-loop iteration variable (i in my case) converted to a string.
2. Rather than having 8 callback functions (4 txbd, 4 axbd), only 1 is needed. Add a field called 'ID' when initializing axes and texts in OpeningFcn and set it equal to the iteration variable. This 'ID' value can then be used in the 1 callback function to find out which tab button has been pressed.
To find out which tab was previously selected, loop through each panel; the one that has visibility 'on' corresponds to the tab that was previously selected.
This is very simple and we can add many tabs..
This simple example got me quickly off and running.
i forget vote XD
i am new working with guide in matlab, i have a question, i need big tabs but i cant create it because the editor size is too short for 3 or 4 big panels.
What can i do?
Well done. Worked properly after changing testTab to simpletab in the code.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!