MATLAB Community

MATLAB, community & more

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Putting the tab into a GUI 21

Posted by Michael Katz,

One of our intrepid readers, Ahmet, recently emailed me asking support for tab panels in GUIDE. After getting myself past “why would anyone want to use tabs?” I started to think about the problem a little bit. My first instinct was a Java solution where I would cram a Java JTabbedPane in a figure window, but I quickly discarded that idea as MATLAB-unfriendly and full of undocumented hooks.

Then I thought about emulating tabs with a row of buttons that controlled the visibility of overlapping panels. Finally, it occurred to me that someone else has probably already thought of that and put it on the File Exchange. In fact last week’s File Exchange Pick of the Week includes an example GUI (GUI_35.m) that shows how to this:

Matt Fig's sample GUI #35 - tabs

The two important properties of the pane’s you’re switching in and out are Position and Visible. Matt Fig’s gui is pretty good but requires setting the visibility of all the components individually. If we put all our controls and axes for each “tabbed pane” on a uipanel, then we can show/hide them all at once by controlling the panel’s Visible property. Here is a quick and dirty sample of a toggle button callback that shows its panel (tab_panel1) and hides the other (tab_panel2). There would be an parallel callback for togglebutton_tab2:

% --- Executes on button press in togglebutton_tab1.
function togglebutton_tab1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton_tab1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

That’s the basic idea. We hope to support a more natural tabbed panel mechanism in GUIDE in the future, but for now you have to build it yourself or use one of the file exchange submissions.

I’d like to go back to my initial surprise about the user’s request for the tabs in the first place. Tabs have several drawbacks. First off you have to come up with a logical grouping for the individual panel controls so each group makes sense, and such that all the tabs as a collection makes sense. Sometimes there is a very natural group, and that’s great; however I’ve seen a lot of GUIs is with a “misc” or “other” tab, or a panel with three related and one unrelated item. If you go this route, make sure your users will understand what is on each panel and why. The second issue is lack of discoverability. Because you have chosen to hide a significant portion of the GUI from your user, you run the chance that he will not see or care to click on the tabs to discover the rest of the functionality.

With those issues in mind, when is the right time to use tabbed panels? This discussion from Designing Interfaces (the author uses the generic term “Card Stacks”) indicates a good time is when (1) there’s too many controls to fit on the screen (2) there’s not a rigid structure (like in our Property Inspector), and (3) the user doesn’t need to work with all of them at the same time (e.g. should you use subplots instead of one axes-per-tab?).

Let us know if you’ve created Tabbed panes in your MATLAB GUIs and if they were effective or not.


Comments are closed.

21 CommentsOldest to Newest

Rodney Thomson replied on : 1 of 21
I have used the hidden Panel method in a number of my MATLAB GUIs. For one a had different sets of controls dependent upon the mode a user selected (via a ComboBox). Each set of controls was on its own panel and the ComboBox changed callback simple hid/showed the relevent panel (using the Visible property). In one particular example I specifically wanted Tabs. I wanted to enable/disable access to differing views of data depending on what data the user had made available. Example screenshot here:
Yair Altman replied on : 2 of 21
Matlab itself has built-in support for tab panels using the uitab and uitabgroup functions. These functions are very useful for simple tab panels. They are very easy to use and save much of the necessary plumbing that users would otherwise need to code by hand. The result also looks much more polished and professional than a button-based tab GUI. The down side is that while uitab and uitabgroup have a good internal help section (type or edit uitab.m and uitabgroup.m to see it), these are unsupported and have no official documentation. So, while they have worked on Matlab 7+ for many years, they may well change or even disappear in the future, maybe even in the very next release. - Yair
Yair Altman replied on : 3 of 21
Interested users can also use the built-in tabdlg function, which (like uitab & uitabgroup) has existed for many years and is unsupported (tabdlg has a valid help section but no doc page). Unlike uitab/uitabgroup which rely on undocumented Java functionality, tabdlg uses plain-vanilla Matlab and as far as I could tell does NOT rely on any undocumented functionality. Unfortunately, the resulting tabs look less polished/professional than uitab's, so that's the trade-off. - Yair
Matt Fig replied on : 4 of 21
Hello Mike, When I was making that particular example, I thought about using uipanels but decided against it. The main reason is that the titleposition property is not continuously adjustable. So setting up the titles in such a way that they are next to each other (as the toggle buttons are in the example GUI you have pictured above), would require more upfront effort and fiddling with the sizes, amount of overlap, etc., to make the panels look natural. Granted, the approach I took requires more under the hood maneuvering. Is there a reason why the location of the title on uipanels is not continuously adjustable? Thanks, Matt
Rodney Thomson replied on : 5 of 21
Yair, Thanks for bringing uitab to my attention. I'm rather annoyed at myself that I did not know this existed prior to hand coding my own tabs!
jiro replied on : 6 of 21
I would say that tabs will be useful when representing different items of a similar type. For example, tabs can represent results from multiple tests. Each tab may contain textual and graphical data for each test, and they all are similar in format. That's how MATLAB and many other applications use tabs. MATLAB has "tabs" when we dock the editor and have multiple files open, or dock multiple figures. A web browser has multiple tabs for various pages.
Mike replied on : 7 of 21
@jiro, Good point. I was thinking more along the lines of the cardstack for increasing the amount of controls available in a small window or directing workflows, and not so much about a multiple document interface. I haven't seen too many MATLAB GUIs do that. I don't know if that's because it's difficult to do in GUIDE, or that's there's a lot of overhead with creating those panels on the fly, or that the people I've talked to generally work with only one set of data at a time.
tim replied on : 8 of 21
As I read this post in a tabbed browser with Matlab's tabbed editor and an Outlook tabbed calendar entry in the background I'm a bit surprised by the question "who would want to use tabs".
Ahmet replied on : 10 of 21
Wow, it is really nice of you to post a topic regarding my question. It is Ahmet, not Ahmed though :) The reason why I am using GUIs is that, I have multiple algorithms designed to solve the exact same problem. Their outputs are the same (or similar) but their parameters are all different. I wanted to separate the input boxes for each for clarity. Thanks again.
Mike replied on : 11 of 21
@Ahmet, 1,000 apologies! I've updated the posts' text. Getting a person's name wrong is one of my biggest fears and in nearly 5 years at MathWorks, I've only done twice that know of, and both in the last two weeks! Are you comparing the outputs of the different algorithms? If so wouldn't they be easier to compare if they overlapped or were on subplots?
Ahmet replied on : 12 of 21
Let's say I have a panel to gather inputs. However, I have many algorithms, and their parameter sets are different. Hence, I am separating (actually, intending to separate) them using tabs. To the right side of the GUI, I have a different panel, which does not contain tabs. Here, I have several plots. In this panel, I can compare the outputs on different plots, on the same plot, or using subplots. That was my intention and the reason I sent you my query about tabs in MATLAB GUIs. Btw, I am impressed by your kindness. Appreciated.
Jorg replied on : 13 of 21
Mike, thanks for your posting. I agree with a lot of the responses in that tabs are extremely useful (even necessary) for a lot of applications. For example, we have developed a Matlab program that calculates the point spread function of a microscope, which requires a lot of different parameters. Right now, the user interface is very dense and cluttered, and using tabs for different parameter groups (such as those related to file I/O, parameters for setting up the calculation, coverslip parameters, parameters related to the optical system) will not only help the user find his way through the parameter space, but will also make the GUI smaller in size - currently, it is so large that it doesn't display properly on smaller laptop screens! The same tab approach is, btw, used in many programs that were developed for super-resolution microscopy, and for the exact same reasons.
allie replied on : 14 of 21
tabs are important when you have a 5" screen (panasonic toughbook u1) I'm going to use this method!
Baskaran replied on : 15 of 21
Hi Mike, I am running a sumulink model, which runs on 0.001 simulation time (fixed time step). This model is almost running on real time through an s-function, which slows down the model when it is faster than the real time. I have developed a GUI to show up some updates from the model in the same time step. The GUI slows down the model significantly. As we are measuring some time data through the model, the speed need to increased. Can you please give some suggestions to improve the speed.
Michele replied on : 16 of 21
I'm working on a GUI which will set different kinds of plots (cartesian, polar and so on) and using tabs to set the properties of each kind of plot seems like a natural choice to me. I plan to use the uitab and uitabgroup suggested by Yair; can anybody tell me anything about what might happen about them in the future? Does anybody know how do they behave in a compiled program? Thank you very much Michele
Todd Welti replied on : 17 of 21
Late post, but: Just wondering if there are any known issues with compiling a standalone matlab app when using uitab/uitabgroup?
Mike replied on : 18 of 21
@Todd, That will depend on the version, but I don't think we post bug information on unsupported functions, so I wasn't able to find anything specific.
Brett Ables replied on : 19 of 21
I am using Matlab to automate several command line style programs that run in sequence. I'm using Matlab to automate gathering all the settings needed to create input files for each of the programs, run each program with the correct inputs, then interpret the output files and plot the results. In this case I would use 1 tab for setting up the user's directories, so that the GUI knows where to find each of the programs, and the input and output folders. Since these are engineering codes that perform flow and combustion analysis the next tabs would be geometry information, flow information, and chemistry information. Finally the last tab would provide the means to generate output plots. In this case, as with many programs I've seen for automating a multi-step analysis process, the order of the tabs logically follows the analysis workflow. Bundling all those settings and functions on a single GUI, or hiding them in menus, would be less user friendly and less effective in my opinion. Each tab contains inputs, functions, or information that depends on or relates to other information on the same tab. Discoverability in this case isn't as much of an issue because the use of each tab is required to perform the analysis.
Richard replied on : 20 of 21
I too wonder why you find it strange that someone would want to use tabs when you are a developer of a piece of software that uses them extensively in the UI, i.e. Matlab??? I am writing a GUI which simulates three different types of component in a larger subsystem. I would like each component type to have its own tab to set its specific parameters, and the other visible controls to set the parameters of the larger system. Just another example to build a case for documenting these properly in help and improving them, providing examples etc.
Jorge Matos replied on : 21 of 21
Tabs are more than useful, they are necessary !! What a shame for an expensive program like matlab wont provide support for tab functions. I would say : improve your overall GUI builder, make it look more professional. I know many ppl dont use matlab because of poor GUI-building capabilities, compared to , like, python.