Programmatically add AppDesigner uicontrol
1 次查看(过去 30 天)
显示 更早的评论
I have a CSV file with a list of m-files, and I want an AppDesigner GUI to have 1 button per m-file. Let's pretend all each button does is call "edit(mfile#)" for the appropriate number. Since all controls are explicit properties of the app, it gets very angry trying to create controls inside the startupFcn. It also does not seem to like using the GraphicsPlaceholder to pack multiple controls into a single app property.
I'm using a workaround that is effective for my current need, but might not be next time. I know the maximum number of m-files, and declaring an app property as a button doesn't actually create the button. So, I manually create the maximum properties, then fill as I read the CSV file.
Any other thoughts or suggestions?
0 个评论
回答(2 个)
Sean de Wolski
2016-6-6
How's this?
fig = uifigure;
panel = uipanel(fig,'Position',[1 1 500 500]);
bg = uibuttongroup(panel,'Position', [50 50 100 500]);
n = 10;
g = gobjects(n,1);
for ii = 1:n
uibutton('Parent',bg,'Position',[10 ii*30 50 30])
end
5 个评论
Sean de Wolski
2016-6-8
You can add a property in the app that would be a structure that contains the buttons, you can then change that structure as you add buttons.
Arsalan jamialahmadi
2019-2-6
I have the same issue . I have created the structure and saved the handle inside the structure:
app.index=app.index+1;
c=uibutton(app.InterfaceTab);
app.a.b(app.index)=c;
But now there is no way to call the stored handle. Following code gives error:
Error: Unable to perform assignment because dot indexing is not supported for variables of this type.
width=100;
app.a.b(app.index).Position(3)=width;
J. Webster
2016-6-6
Instead of generating buttons, I think it would be better to populate a Drop Down with the names of the files, and open them that way, either on a selection changed callback, or with a separate button that opens the file based on the current selected value.
Generating buttons on the fly is generally never done for a reason.
2 个评论
J. Webster
2016-6-8
functionally of course they'd be the same. The main issue for me is layout. I suppose if you know you'll never have more than a few buttons, it may not be a big deal. But what if you have 15? 33? or more? Obviously it could be problematic.
Also, how do you generate the callbacks for when the buttons are pressed?
I understand about customers and all, but this is just a really bad way to do it.
另请参阅
类别
在 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!