Migrating popupmenu from guide to app designer
조회 수: 1 (최근 30일)
이전 댓글 표시
I have an application based on guide that uses the popupmenu control. The dropdown control available in app designer does not have the same capabilities, such as changing the items at run time.
댓글 수: 2
Tommy
2020년 4월 20일
This was a simple app I wrote a few days ago which updates the items in a drop down based on the value of a slider. Other properties of the drop down, such as 'ItemsData' and 'ValueChangedFcn', can be updated in a similar manner. Are you looking for something like this?
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
DropDownLabel matlab.ui.control.Label
DropDown matlab.ui.control.DropDown
SliderLabel matlab.ui.control.Label
Slider matlab.ui.control.Slider
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: Slider
function SliderValueChanged(app, event)
value = app.Slider.Value;
app.DropDown.Items = compose('Option %d', 1:(floor(value/20)+1));
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create DropDownLabel
app.DropDownLabel = uilabel(app.UIFigure);
app.DropDownLabel.HorizontalAlignment = 'right';
app.DropDownLabel.Position = [68 319 66 22];
app.DropDownLabel.Text = 'Drop Down';
% Create DropDown
app.DropDown = uidropdown(app.UIFigure);
app.DropDown.Items = {'Option 1'};
app.DropDown.Position = [149 319 100 22];
% Create SliderLabel
app.SliderLabel = uilabel(app.UIFigure);
app.SliderLabel.HorizontalAlignment = 'right';
app.SliderLabel.Position = [322 330 36 22];
app.SliderLabel.Text = 'Slider';
% Create Slider
app.Slider = uislider(app.UIFigure);
app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
app.Slider.Position = [379 339 150 3];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
채택된 답변
Ajay Pattassery
2020년 5월 28일
If you want to control the drop-down menu during runtime, create the drop-down menu programmatically.
The property 'Items' can be used to control what all to be listed in the drop-down menu.
Also, the 'Parent' property can be used to control where the drop-down menu needs to be placed. The position can be further finetuned by adjusting the 'Position' property.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!