Putting the tab into a GUI
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:
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) set(handles.tab_panel1,'Visible','Off'); set(handles.tab_panel2,'Visible','On');
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.
- Category:
- MATLAB GUI
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.