Update string with new line in edit Field (text) in mlapp
36 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Voss
il 7 Dic 2023
"If you want to allow multiple lines of text, use a text area component instead of an edit field."
Risposte (1)
Image Analyst
il 5 Dic 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 Commenti
Image Analyst
il 7 Dic 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???
Vedere anche
Categorie
Scopri di più su Startup and Shutdown 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!