GUI Popup Menu and Listbox Default
Show older comments
Hi all,
I'm using a listbox and a popup menu in my Matlab GUI. They both have 3 items/options each.
Now when I run the GUI, the default item showing on the popup menu is option 1. The default item highlighted in the listbox is also number 1.
The problem is, these values which I think should be the default values are not used in the program. Some random values are chosen. Sometimes option number 1, sometimes 2, sometimes 3. How do I fix this? I would like the program to run using the option appearing in the popup menu and the one highlighted in the listbox, since naturally the user thinks these options will be used if they want to use them and they don't select them when they run the program as they're already selected. Can anyone help please?
Thanks.
Accepted Answer
More Answers (1)
Image Analyst
on 25 Nov 2014
I have no idea why it's selecting random indexes for your popup and listbox (it never does that for me), but you can set them to what you want. First, unless you specified options in the string property of GUIDE, you'll need to write and call a function to load them up. For example in my OpeningFcn function I call a function I wrote called LoadUpListBox(handles). This loads up the listbox with a bunch of images in the folder I want.
So, once you have the listbox and popup loaded with items, you can specify the item you want to be the default. For example let's say you want item #2 in the listbox to be preselected and item #3 in the popup to be selected. In your OpeningFcn, after the controls are loaded, you set the selection with set():
set(handles.listbox1, 'Value', 2);
set(handles.popup1, 'Value', 3);
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!