How can I access (to change) a numeric edit field Label once the component name is modified using App Designer?

67 ビュー (過去 30 日間)
Richard
Richard 2022 年 12 月 25 日
回答済み: Divyanshu 2023 年 4 月 17 日
I'm building a complex application in App Designer. I'm attempting to use the Label field to indicate the units of measure for the numeric field data. This information may change at runtime depending on the configuration of the application. My test application, slice below, demonstrates that changing the component name from the default of say 'EditField' to 'abc' does not change the Label component from 'EditFieldLabel' to 'abcLabel'. This being the case I can't access the label field by concatenating the edit field and 'Label'. Only the 'unedited' sample works at runtime since it appears App Designer does not modify the name of the Label component when the numeric field component name is changed.
Unless I'm missing something my only option left is to create the labels separately with the required component names as in 'abcLabel', but if there is a workaround to access the component Labels that I've already created that would be helpful; they don't appear in the list of components.
  2 件のコメント
Richard
Richard 2022 年 12 月 26 日
I would still be interested in getting the original implementation to work, but in the end I created standalone Label components and renamed so they can be addressed with the underlying code. The label component for a numeric edit field 'abc' is named 'abcLabel' and the label is updated using app.abcLabel.Text = 'new label'
James Squire
James Squire 2023 年 2 月 20 日
I have a similar problem. I would like to make both the numeric field and its attached label invisible at times. Setting the app.textfield.Visible to false only makes the numeric field invisible, not the label. There appears to be no way to directly modify the numeric input field's label if created in app designer.

サインインしてコメントする。

回答 (2 件)

Benjamin Potter
Benjamin Potter 2023 年 4 月 13 日
Hi,
The issue you are facing is that unlike with other ui elements, matlab does not modify the label names for edit fields (not sure why though). If you go to the Component Browser and right click there is an option to include component labels. Using this you can now modify your label names to match the edit field names as you see fit, and can them modify in code as you see fit.
Hope this helps.

Divyanshu
Divyanshu 2023 年 4 月 17 日
Directly it is not possible that the changes made in the component(edit-field) name automatically change the name of corresponding label as well. This is because the Label is a separate component that is automatically created by App Designer when you add an EditField to your app.
  • One workaround you could consider is to use the findobj() function to locate the label component based on its properties rather than its name. For example, you could give your label component a specific tag value, and then use findobj() to search for components with that tag here is the sample code:
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.EditFieldLabel.Tag = 'EditFieldLabel';
% Find the label component based on its tag
myEditFieldLabel = findobj(app.UIFigure, 'Tag', 'EditFieldLabel');
% Update the label text
myEditFieldLabel.Text = 'NewComp';
end
end
In the above demo app, I have renamed the component from component browser as ‘NewComp’. But the label remains as EditFieldLabel.
If this does not work for your specific use case, then creating separate label components with the required component names may be the best solution.
For more details about findobj function refer the following documentation:

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by