Filter löschen
Filter löschen

Programmatically add AppDesigner uicontrol

4 Ansichten (letzte 30 Tage)
Greg am 6 Jun. 2016
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?

Antworten (2)

Sean de Wolski
Sean de Wolski am 6 Jun. 2016
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])
  5 Kommentare
Sean de Wolski
Sean de Wolski am 8 Jun. 2016
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
Arsalan jamialahmadi am 6 Feb. 2019
I have the same issue . I have created the structure and saved the handle inside the structure:
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.

Melden Sie sich an, um zu kommentieren.

J. Webster
J. Webster am 6 Jun. 2016
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 Kommentare
Greg am 6 Jun. 2016
I completely agree, but I have customers, and they don't like the extra mouse clicks associated with dropdowns.
However, how is generating them "on-the-fly" inside startupFcn any different from inside AppDesigner's automatically generated class constructor? They're the exact same MATLAB commands being executed one line a time either way.
J. Webster
J. Webster am 8 Jun. 2016
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.

Melden Sie sich an, um zu kommentieren.


Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by