seting default property values for uifigure graphics
4 views (last 30 days)
Show older comments
I would like to set default properties for some uifigure base graphics such as uilabel, uitextfield etc.
The documentation suggests this should work. It worked in many yerars with figure based graphics. When I try setting defaults for uifigure base graphics I get the same error message testing different defaults! - see statement below below.
Is there a simple solution. - I would like to start using uibased graphics. However, I like using defaults (and sometimes I like changing the factory settings).
Morten
set(groot, 'defaultuipanelhorizontalalignment', 'right') % setting 'Default for horizontalalignment in an uicontrol
0 Comments
Answers (1)
Walter Roberson
on 27 Feb 2023
You need to set against ['default' classname PropertyName] and it must be a property that exists in the class.
You cannot say, for example, that within uipanel that the default font should be whatever, because uipanel do not have a font property.
What you can do is set a default against a particular object instead of against groot. You can set the default uipanel createfcn for groot, to be a function that takes the handle of a uipanel being created and applies a default against the object. For example
set(src, 'defaultTextHorizontalAlignment', 'center')
3 Comments
Walter Roberson
on 27 Feb 2023
You can set a default property against groot, in which case it applies for all further graphics objects of the appropriate type that are created, unless the property has been overriden by a more specific default setting or by specific properties at individual graphics object construction time.
You can set a default property against a particular container object (such as a figure or uipanel) in which case it applies for all further graphics object of the appropriate type that are created within the container object (unless there is some overriding setting.)
However, you cannot set a default property against a class of container objects to control properties that are not properties of that kind of container. Only against instances of the class.
figu = uifigure();
panu = uipanel(figu);
set(panu, 'defaultuicontrolHorizontalAlignment', 'right');
That would apply to all uicontrol created within panu after that time (unless there was further overwriting of properties). But you cannot do
set(groot, 'defaultuipaneluicontrolHorizontalAlignment', 'right')
to try to say that within uipanel that uicontrol HorizontalAlignment is to default to the given value.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!