is there a way to change a certain line using sprintf in textbox in app designer

i have the code set up to display sertain lines in a text box using a sting so they can be added or removed with their certain values but i am also trying to change this color.
% In properties
fpmc='Flatpack MC';
%%
%% in done push buton call back
fpc1=app.FlatpackMcCheckBox.Value;
fpqt1=app.MCQTEditField_2.Value;
jfpt=(50/(app.JoeFlatpackEditField.Value));
dfpt=(50/(app.DavidFlatpackEditField.Value));
nfpt=(50/(app.NickFlatpackEditField.Value));
afp=[jfpt,dfpt,nfpt];
atfp=mean(afp);
ttfp1=atfp;
ttfp2=atfp*2;
ttfp3=atfp*3;
fpqt1t1=fpqt1/ttfp1;fpqt1t2=fpqt1/ttfp2;fpqt1t3=fpqt1/ttfp3;
fpmct1 =[fpqt1t1, fpqt1t2, fpqt1t3]';
fpmct2 =[fpqt1t1/60,fpqt1t2/60,fpqt1t3/60]';
prod=strings(1,14);
p=0;
if fpc1==1&&fpqt1>0
if tth==1
fp1= "%s\t: %.0f %.1f %.1f %.1f"; %s disp Flatpack mc \t(tabs) %.1f is the number value
prod(p+1)=sprintf(fp1,app.fpmc,fpqt1,fpmct2(1),fpmct2(2),fpmct2(3));
p=(p+1);
elseif ttm==1
fp1= "%s\t: %.0f %.2f %.2f %.2f"; % save as above
prod(p+1)=sprintf(fp1,app.fpmc,fpqt1,fpmct1(1),fpmct1(2),fpmct1(3));
p=(p+1);
end
app.ProductTextArea.Value=prod;
the fp1 is the line i want to change the color of to like yellowish green. the entire if statment is multiplied by like 14 for each different item which i want to be another color.

6 comentarios

In general the text color will be the same for each text object. You will have to split your text over multiple objects, or find a way to turn only 1 line a different color.
You can give uihtml component a try.
uihtml supports html. So you will need to generate your text in html format. Then you can set this text as HTML Source
a = uihtml;
a.HTMLSource = '<p style="color:#FF0000";>Red paragraph text</p><p style="color:#0000FF";>Blue paragraph text</p>';
@Mohammad Sami this looks like an answer to me. Feel free to repost it as such.

Iniciar sesión para comentar.

 Respuesta aceptada

uihtml supports html. So you will need to generate your text in html format. Then you can set this text as HTML Source
a = uihtml;
a.HTMLSource = '<p style="color:#FF0000";>Red paragraph text</p><p style="color:#0000FF";>Blue paragraph text</p>';

4 comentarios

How do i keep the %.1f in that so it pulls in the variables to display?
You can still construct the char array with sprintf (either by concatenating the parts or putting everything in a single call).
So how do i call the html code into the textbox or the sprintf into the html?
Like this you mean?
a = uihtml;
a.HTMLSource = [...
'<p style="color:#FF0000";>' sprintf(fp1,app.fpmc,fpqt1,fpmct1(1),fpmct1(2),fpmct1(3)) '</p>',...
'<p style="color:#0000FF";>' sprintf('%.1f',val) '</p>';

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Programmatically en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 24 de Jun. de 2021

Comentada:

Rik
el 25 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by