uitextarea not displaying correct font

I'm editing code that was exported from the app designer to create a GUI. I want the user to edit code directly in a textbox of the GUI. The textbox is child of a tab in a tab group, which is a child of the uifigure.
The GUI will not display fonts in the TextArea object with any font other than MATLAB's default. All attempts to render with a different font fail.
Here are my attempts
Attempt 1
desiredFont='Monospaced';
app.SpecifyconfigurationinformationTextArea = uitextarea(app.ConfigurationInformationTab,'FontName',desiredFont);
app.SpecifyconfigurationinformationTextArea.Position = [102 17 329 412];
app.SpecifyconfigurationinformationTextArea.Value = loadOldConfigCommand(app);% just returns a cell array of strings;
Attempt 2
desiredFont='Monospaced';
app.SpecifyconfigurationinformationTextArea = uitextarea(app.ConfigurationInformationTab);
app.SpecifyconfigurationinformationTextArea.FontName = desiredFont;
app.SpecifyconfigurationinformationTextArea.Position = [102 17 329 412];
app.SpecifyconfigurationinformationTextArea.Value = loadOldConfigCommand(app);% just returns a cell array of strings;
I have also tried other fonts
desiredFont='FixedWidth'; % fails
desiredFont='Times New Roman'; % fails
desiredFont='Comic Sans'; % nope
desiredFont='Courier New'; % fails
No matter what I do, when the app renders it renders like this (closing all windows and clearing all variables between attempts)

Risposte (2)

Mario Malic
Mario Malic il 21 Ott 2020
Modificato: Mario Malic il 22 Ott 2020
FontName is not a valid Name-Value pair argument. You can change font after you create text box.
app.SpecifyconfigurationinformationTextArea.FontName = 'Monospaced';

5 Commenti

James Johnson
James Johnson il 24 Ott 2020
Modificato: James Johnson il 24 Ott 2020
Thanks for taking an interest.
That's already listed as one of the solutions I tried ("Attempt 2"). No dice, it also fails.
Also "Attempt 1" does not return an error. AFAIK if it was not a valid Name-Value pair it would return an error? I see that it's not listed in the documentation, but it might still be valid.
Mario Malic
Mario Malic il 24 Ott 2020
Modificato: Mario Malic il 24 Ott 2020
I tested out the attempt 2 and it works for me. I ran a demo app from command window, and ran the command through command window. Can you check interactivity panel on the your Text Editor, if Editable property is enabled?
James Johnson
James Johnson il 26 Ott 2020
Modificato: James Johnson il 26 Ott 2020
Editable property is enabled. It does not work on R2020a, but does work on R2020b. So I just upgraded.
Mario Malic
Mario Malic il 26 Ott 2020
Modificato: Mario Malic il 26 Ott 2020
Alright, I guess that might have been a bug that has been fixed meanwhile. I am on 2020b as well.
FontName is a valid name-value argument in the release documented by OP (r2020a).
I'm also having trouble applying FixedWidth to many uicomponents such as uibutton, uispinner, uilabel etc. It acceps consolas but not FixedWidth which is supported in many graphics objects that contains a FontName property (ie, text).

Accedi per commentare.

Adam Danz
Adam Danz il 31 Mar 2021
Modificato: Adam Danz il 7 Apr 2021
I have the same problem of assigning 'FixedWidth' font to FontName properties in several uifigure components such as uibutton, uilabel, uispinner, using Matlab r2021a.
FixedWidth is used in very may graphics objects to specify whatever the default fixed width font is for the sytem (ie see text > FontName). But assigning it to the obejcts listed above resulted in the default font (not fixed width) which is what happens when a font name is not recognized. But when I assign other font names such as consolas it works fine.
Solution
What worked for me was assigning the default fixedwidth font name directly from root properties using,
h = uibutton(___,'FontName', get(groot, 'FixedWidthFontName'))
Update
MW tech support have confirmed that the fixedwidth option is not yet implemented for uicomponents (r2021a). My solution above is the best workaround until then.

2 Commenti

Mario Malic
Mario Malic il 2 Apr 2021
Modificato: Mario Malic il 2 Apr 2021
Hi Adam, your issue might be related to this one: properties of some components are not properly changed during their creation (includes when you change properties in StartupFcn). Try drawnow before changing the component properties.
Adam Danz
Adam Danz il 2 Apr 2021
Modificato: Adam Danz il 2 Apr 2021
Thank Mario Malic, good hunch, but that's not the problem in this case. FixedWidth merely isn't recognized at all as a valid fontname in the app designer components that I tested.
Evidence:
  1. It's not an option in the FontName dropdown list within AppDesigner design window.
  2. Even when the app is fully rendered and paused in debug mode within a callback function, changing the FontName of a component to FixedWidth from the command window results in the default font which is the expected behavior when a font isn't recognized (ie, set a fontname to something like app.Thing.FontName='adfladfja')
I reported this to tech support.

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Centro assistenza e File Exchange

Prodotti

Release

R2020a

Richiesto:

il 20 Ott 2020

Modificato:

il 7 Apr 2021

Community Treasure Hunt

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

Start Hunting!

Translated by