필터 지우기
필터 지우기

Programmatically adjusting editor fontsize does not work

조회 수: 15 (최근 30일)
Charles
Charles 2021년 8월 24일
댓글: Jan 2021년 9월 2일
Hello,
I'd like my editor and command window font size to be adjusted automatically when I plug in an external monitor to my laptop. I've looked at this link, but the advice does not seem complete because it doesn't work. In addition, it's not clear what setting should be modified, since I'd like to change two settings but can only find one relevant setting.
>> s = settings;
>> s.matlab.fonts.codefont.Size
ans =
Setting 'matlab.fonts.codefont.Size' with properties:
ActiveValue: 10
TemporaryValue: <no value>
PersonalValue: 10
FactoryValue: 10
>> s.matlab.fonts.codefont.Size.TemporaryValue = 12
s =
SettingsGroup with properties:
matlab: [1×1 SettingsGroup]
>> s.matlab.fonts.codefont.Size
ans =
Setting 'matlab.fonts.codefont.Size' with properties:
ActiveValue: 12
TemporaryValue: 12
PersonalValue: 10
FactoryValue: 10
This works without error in the command window, but there is no effect in the editor window - font stays same size. Furthermore, opening the "Preferences" window to "Preferences->Fonts->Custom: Editor" shows the font size is still 10.
I'd also like to adjust the size of the command window font. There is nothing obvious in the settings object hierarchy where this might be done.

답변 (4개)

Jan
Jan 2021년 8월 24일
편집: Jan 2021년 8월 30일
Your code changes the values, which are applied at the next start of Matlab.
You can use FEX: CmdWinTool
Font = CmdWinTool('Font');
newFont = java.awt.Font(Font.getName, java.awt.Font.PLAIN, 24); % [EDITED]
CmdWinTool('Font', newFont);
Or directly:
jTextArea = [];
matchClass = 'javax.swing.JTextArea$AccessibleJTextArea';
cmdWinDoc = com.mathworks.mde.cmdwin.CmdWinDocument.getInstance;
cmdWinListener = cmdWinDoc.getDocumentListeners;
for iL = 1:length(cmdWinListener)
if isa(cmdWinListener(iL), matchClass)
jTextArea = cmdWinListener(iL);
end
end
if ~isempty(jTextArea)
Font = jTextArea.getFont;
newFont = java.awt.Font(Font.getName, java.awt.Font.PLAIN, 24); % [EDITED]
jTextArea.setFont(newFont);
pause(0.02); % Voodoo
end

Charles
Charles 2021년 8월 27일
Kind of defeats the purpose when attaching an external monitor if I have to restart Matlab. I'll stick with mousing through the Preferences window. Fortunately, that method does not require a Matlab restart.
  댓글 수: 4
Jan
Jan 2021년 8월 30일
I've edited my answer. Please try it again. There is no setSize method for the fonts.
Charles
Charles 2021년 8월 31일
Thanks for the corrections, the code works perfectly to set the command window font.
Infortunately, it is not obvious how to convert those commands to get the editor window font to change. Modifying the com.mathworks.mde.cmdwin.CmdWinDocument.getInstance invocation might be the right strategy, but this command is completely opaque.

댓글을 달려면 로그인하십시오.


Jan
Jan 2021년 8월 31일
An easier version to set the desktop and editor font immediately:
s = settings;
% Set temporarily until next start of Matlab:
s.matlab.fonts.codefont.Size.TemporaryValue = 24
% Or permanently:
s.matlab.fonts.codefont.Size.PersonalValue = 12;
% In the editor only - ?!
s.matlab.fonts.editor.normal.Size.TemporaryValue = 14
See:

Charles
Charles 2021년 9월 1일
This immediately changes the font in the command history window and no other window:
s.matlab.fonts.codefont.Size.TemporaryValue = 24
This refers to a non-existent normal element:
>> s.matlab.fonts.editor.normal.Size.TemporaryValue = 14;
Unrecognized method, property, or field 'normal' for class 'matlab.settings.SettingsGroup'.
This is certainly correct syntax but has no immediate effect on anything:
s.matlab.fonts.editor.codefont.Size.TemporaryValue = 24
With this, we are back to my very first comment in this thread.
  댓글 수: 1
Jan
Jan 2021년 9월 2일
Is this an answer or a comment to my answer? In the latter case, please use the section for comments.
On my Win10/MatlabR2018b computer, this command changes the font in the editor directly. You can try to rename your current preferences folder (see: prefdir), during Matlab is not running. Then the next start of Matlab recreates this folder with the default values. Then try again, if the settings methods can modify the command window and editor window directly.
Please mention, which Matlab and OS version you are using. It is possible, that different Matlab versions use different methods of the settings object. Take my suggestions as startpoint for your own investigations.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 System Commands에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by