MATLAB Answers

Jana
0

interactive GUI: pup-up menus, list

Asked by Jana
on 5 Mar 2015
Latest activity Commented on by 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

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 5 Mar 2015
 Accepted Answer

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

Show 1 older comment
Jana - yes, the refresh functions can be defined anywhere in the GUI m file.
I'll define a refresh function to each menu/listbox, and I'll run it from the callbacks, e.g. from callback of menu1 I'll call the refresh function for the menu2.
Yes, you could do that so long as you know how to refresh menu 2 given the change to menu 1.
I can do refreshPopupMenu1(hObject,handles); set(hObject,'String','whatever') but how I say to which menu/listbox it refers?
Remember that handles is a structure that has (at least) fields for handles to all of the controls. So to get the handle to popupmenu1 just do
handles.popupmenu1
Do something similar whenever you need to access the other controls via their handle.
And how do I force the action to happen?
Which action are you referring to?
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
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.