uitextarea not displaying correct font

7 次查看(过去 30 天)
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)

回答(2 个)

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

请先登录,再进行评论。


Adam Danz
Adam Danz 2021-3-31
编辑:Adam Danz 2021-4-7
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 个评论
Mario Malic
Mario Malic 2021-4-2
编辑:Mario Malic 2021-4-2
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 2021-4-2
编辑:Adam Danz 2021-4-2
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.

请先登录,再进行评论。

类别

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

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by