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

37 visualizaciones (últimos 30 días)
ML_Analyst
ML_Analyst el 5 de Dic. de 2023
Comentada: Voss el 7 de Dic. de 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 comentarios
ML_Analyst
ML_Analyst el 7 de Dic. de 2023
Tried this.. but doesn’t work too ,also I have some variables in between too
Voss
Voss el 7 de Dic. de 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."

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 5 de Dic. de 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 comentarios
ML_Analyst
ML_Analyst el 7 de Dic. de 2023
Thanks , but for my use case thinking it’s better to use edit text field
Image Analyst
Image Analyst el 7 de Dic. de 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???

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by