interactive GUI: pup-up menus, list

1 view (last 30 days)
Jana
Jana on 5 Mar 2015
Commented: Geoff Hayes on 10 Mar 2015
Hi,
I am making a small interface where the objects interact with each other. Specifically: I have 2 popup menus and a list, and some buttons. - I populate the popup menus at the beginning. When user selects one item in one of the menus, the other changes the items accordingly (only items relevant to the selected) and vice versa. - When user pushes button "Select", the data from popup menus are added to the list. - When user selects an item in the list and clicks on button "remove", the item will be removed.
I can read the data and stuff them into handles, even into the menus and the listbox, but I don't know how to re-generate the menus/list. When I put popupmenu1_CreateFcn into a callback of popupmenu2, it changes the popupmenu2 instead of 1. The same, when I put listbox_CreateFcn into the callback of a button, it will stuff the things into the button. How can I say "now refresh the (relevant) menu/list"?
Thanks,
Jana

Accepted Answer

Geoff Hayes
Geoff Hayes on 5 Mar 2015
Jana - the _CreateFcn only gets called when the GUI is launched and the widgets/controls are created. You do not want to be calling this function once the GUI is running. If you have added code to this function that you wish to invoke at a later time, then you should put it in a separate function (still saved in your GUI m file). Something like
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% invoke function to populate/refresh popupmenu1
refreshPopupMenu1(hObject,handles);
where
function refreshPopupMenu1(hObject,handles)
% do stuff
Then, in your callback for the second popup menu, you would do something like
function popupmenu1_Callback(hObject, eventdata, handles)
refreshPopupMenu1(hObject,handles);
You would do the same for the other popu menu and list box.
  4 Comments
Geoff Hayes
Geoff Hayes on 9 Mar 2015
Jana's answer moved here
Hi,
Apparently, once I re-set the handles, the menus refresh as well. So it seems that I don't need the refresh function, I only put the line set(handles.popupmenu_threats, 'String', {char(threats)}); into the callback of the other popumenu and it works.
Almost well. I have one menu with islands, the other with threats living on them. When I select an island, the threats menu shows the threats living there and vice versa. The problem comes when I have threats A, B, C in the threat menu, and I select an island, where only threats D, E live. Then, the whole threats menu vanishes. It does find the proper list of new threats, but it eats up the whole menu. Any idea what to do? :-(
This doesn't happen at the beginning, when I play with one menu. It happens when I already clicked on the menu which disappears (I did a selection).
Cheers,
Jana
Geoff Hayes
Geoff Hayes on 10 Mar 2015
Then, the whole threats menu vanishes.
Jana - do you mean that the menu disappears from the GUI? What do you mean by ..but it eats up the whole menu? Please attach a screen shot so that it becomes clear what is happening.

Sign in to comment.

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output 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!