MATLAB: How to change the tabbing order of UICONTROLS in the GUI

guiMATLABordertabtabbing

I would like to control the order in which the usage of the 'Tab' key cycles through the UICONTROL objects in my MATLAB figure.

Best Answer

This functionality has been added to MATLAB in the "Tab Order Editor". For more information about setting the tab order, please see our help documentation here,
<http://www.mathworks.com/help/matlab/creating_guis/setting-tab-order.html>
You may access the same page locally by typing the following at the MATLAB prompt:
web([docroot,'/techdoc/creating_guis/f8-998374.html'])
If you are using MATLAB 7.0.4 (R14SP2) or earlier versions, read below for possible workarounds:
There are two ways to change the tabbing order of UICONTROLs in a GUI. The first, which was introduced in MATLAB 6.5 (R13), is to use the Tab Order Editor under the Tools menu in the GUIDE window. This allows you to move items up and down in the tab order.
The second way is to reorder the list of children held in the 'Children' property of the GUI figure. The first thing to note about the tabbing order of UICONTROLs within a GUI when using this technique is that the order in which the UICONTROLS appear in the figure's child list is the reverse of the order in which they will tab. Note that the children being reordered must have the same parent, e.g., if a GUI figure contains a UIPANEL, you must reorder the children of the panel separately.
Also, the order reflected in the child list of the figure is the order in which the UICONTROLs are stacked visually. This means if two UICONTROLs are overlaid, the item higher in the child list will show up on top.
Given that the child order list determines tabbing and stacking order, the utility function UISTACK can be used to manipulate the stack.
For example, to move an item up in the stack, find the handle to that object and then move it using UISTACK:
h = findobj('Tag', TagOfObject);
uistack(h, 'up');
Using UISTACK is the preferred method of manipulating the tab order of UICONTROLs.
Another method to change the tab order of UICONTROLs is to permute the order of the handles of the children of the figure:
1. Assign the vector of Children of the GUI figure to a variable by using the following command:
HandlesOfChildren = get(HandleOfFigure,'Children');
2. Permute the HandlesOfChildren vector as you wish. For instance, to reverse the tab order:
ReversedChildren = flipud(HandlesOfChildren);
3. Reassign the permuted vector to the Children property of the figure:
set(HandleOfFigure, 'Children', ReversedChildren);
NOTE: You can only assign a vector which is a permutation of the vector of children in this manner; you can't, for example, do the following because 0 is not the handle of a child of the figure:
set(HandleOfFigure,'Children',[0 HandlesOfChildren(2:end)]);
Also note that there are also some components that cannot be tabbed. You cannot tab to axes, static text boxes, and ActiveX components.