uitextarea not displaying correct font

9 vues (au cours des 30 derniers jours)
James Johnson
James Johnson le 20 Oct 2020
Modifié(e) : Adam Danz le 7 Avr 2021
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)

Réponses (2)

Mario Malic
Mario Malic le 21 Oct 2020
Modifié(e) : Mario Malic le 22 Oct 2020
FontName is not a valid Name-Value pair argument. You can change font after you create text box.
app.SpecifyconfigurationinformationTextArea.FontName = 'Monospaced';
  5 commentaires
Mario Malic
Mario Malic le 26 Oct 2020
Modifié(e) : Mario Malic le 26 Oct 2020
Alright, I guess that might have been a bug that has been fixed meanwhile. I am on 2020b as well.
Adam Danz
Adam Danz le 31 Mar 2021
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).

Connectez-vous pour commenter.


Adam Danz
Adam Danz le 31 Mar 2021
Modifié(e) : Adam Danz le 7 Avr 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 commentaires
Mario Malic
Mario Malic le 2 Avr 2021
Modifié(e) : Mario Malic le 2 Avr 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 le 2 Avr 2021
Modifié(e) : Adam Danz le 2 Avr 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by