Effacer les filtres
Effacer les filtres

Update string with new line in edit Field (text) in mlapp

26 vues (au cours des 30 derniers jours)
ML_Analyst
ML_Analyst le 5 Déc 2023
Commenté : Voss le 7 Déc 2023
I have a GUI with a edit text box which I will update via my script, but I want to add newlines and the edit text box should update with new lines as I have updated via the script. My code snippet is below
Text_to_update= This is sample testing” + newline + newline + “Results are stored in the output path”;
app.NewEditField.Value= Text_to_update;
But I cannot see the text displayed in 2 lines (with one line space in between) in the Edit Tex field ,it is just displayed in straight line. Could someone help here ?
  3 commentaires
ML_Analyst
ML_Analyst le 7 Déc 2023
Tried this.. but doesn’t work too ,also I have some variables in between too
Voss
Voss le 7 Déc 2023
From uieditfield documentation (under Value property):
"If you want to allow multiple lines of text, use a text area component instead of an edit field."

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 5 Déc 2023
Yeah, kind of weird. But I found that if you make it a Text instead of an Edit box, it will work and show up on multiple lines:
folder = pwd;
selectedFileName = 'whatever.png';
app.TextArea.Value = sprintf('%s\n\n%s', folder, selectedFileName);
  2 commentaires
ML_Analyst
ML_Analyst le 7 Déc 2023
Thanks , but for my use case thinking it’s better to use edit text field
Image Analyst
Image Analyst le 7 Déc 2023
Why? I think not having line feeds in the edit text box may be a bug. You can assign them but it just doesn't show up on separate lines. If you get the values:
% Button pushed function: Button2
function Button2Pushed(app, event)
sText = app.TextArea.Value % Returns cell array.
sEdit = app.EditField.Value % Returns character array.
end
You'll see the difference is the text box value comes back as a cell array with each line of the text box as one cell, and the edit text comes back as a character array.
You can still allow the user to edit the text box and change it, you just have to deal with their input as a cell array, which is no big deal. So for all intents and purposes it seems they are pretty similar and using a text box to capture user input should work just fine. Why do you think it won't???

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by