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

26 次查看(过去 30 天)
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 个评论
ML_Analyst
ML_Analyst 2023-12-7
Tried this.. but doesn’t work too ,also I have some variables in between too
Voss
Voss 2023-12-7
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."

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2023-12-5
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 个评论
ML_Analyst
ML_Analyst 2023-12-7
Thanks , but for my use case thinking it’s better to use edit text field
Image Analyst
Image Analyst 2023-12-7
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???

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by