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'
How can I access (to change) a numeric edit field Label once the component name is modified using App Designer?
90 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1242892/image.jpeg)
2 Commenti
James Squire
il 20 Feb 2023
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.
Risposte (2)
Benjamin Potter
il 13 Apr 2023
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1355093/image.png)
Hope this helps.
0 Commenti
Divyanshu
il 17 Apr 2023
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:
0 Commenti
Vedere anche
Categorie
Scopri di più su Deploy to C++ Applications Using MATLAB Data API (C++11) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!