MATLAB Answers

Luna
0

How to change inputdlg's editbox into a popup menu?

Luna
さんによって質問されました 2019 年 9 月 2 日
最新アクティビティ Luna
さんによって コメントされました 2019 年 9 月 5 日
Hellooo dear community!
I want to create a small dialog box which contains 2 different popup-menu. Do we have any built-in function like that? Or can I change inputdlg's editboxes into popup-menus?
Otherwise I have to create a parent figure which contains Ok, Cancel buttons and two uicontrol objects which are popups. I have to code callbacks for all these and it will be way longer than I expected. That's why I want a short quick solution. Do you have any ideas?

  1 件のコメント

Rik
2019 年 9 月 2 日
I would argue it isn't that much coding. If you don't use GUIDE it shouldn't take more than 10 minutes to throw something together.

サインイン to comment.

製品


リリース

R2018b

1 件の回答

Rik
回答者: Rik
2019 年 9 月 2 日
 採用された回答

I'll be honest, it took me about 15 minutes, but this should to something similar to what you describe:
selection=doubleDropMenu({'a','b'},{'foo','bar'});
function choices=doubleDropMenu(list1,list2)
%Input a char array or a cellstr, the output is the selection, or 0 when
%the user presses cancel.
f=doubleDropMenu__create_GUI(list1,list2);%create GUI
uiwait(f);%wait for OK or cancel
%retrieve output and close
h=guidata(f);choices=h.choices;close(f);
end
function f=doubleDropMenu__create_GUI(list1,list2)
f=figure('menu','none','Toolbar','none');
h=struct('f',f);
h.button_ok=uicontrol('Parent',f,...
'Style','pushbutton',...
'Units','Normalized',...
'Position',[0.1 0.1 0.3 0.1],...
'String','OK',...
'Callback',@doubleDropMenu__Callback);
h.button_cancel=uicontrol('Parent',f,...
'Style','pushbutton',...
'Units','Normalized',...
'Position',[0.6 0.1 0.3 0.1],...
'String','cancel',...
'Callback',@doubleDropMenu__Callback);
h.list1=uicontrol('Parent',f,...
'Style','popupmenu',...
'Units','Normalized',...
'Position',[0.1 0.6 0.8 0.2],...
'String',list1);
h.list2=uicontrol('Parent',f,...
'Style','popupmenu',...
'Units','Normalized',...
'Position',[0.1 0.3 0.8 0.2],...
'String',list2);
guidata(h.f,h)
end
function doubleDropMenu__Callback(hObject,eventdata)
h=guidata(hObject);
switch hObject
case h.button_ok
h.choices=[get(h.list1,'Value') get(h.list2,'Value')];
case h.button_cancel
h.choices=[0 0];
end
guidata(h.f,h)
uiresume(h.f)
end

  1 件のコメント

Luna
2019 年 9 月 5 日
Thanks Rik, actually what I was looking for is a dynamically changing number of popumenus according to inputs I pass to the function. It definetely gave me an idea how to make it.
Thank you for your time and helping me on this :)

サインイン to comment.



Translated by