How do I change the Matlab Desktop font preferences using commands?

1 vue (au cours des 30 derniers jours)
Yair Treister
Yair Treister le 10 Oct 2011
Commenté : juhisteri le 17 Juin 2021
I want to be able to create a shortcut which changes my Matlab Desktop (layout, font sizes, etc..) so that I can have a "Presentor" version of Matlab when I am presenting in a conference room, or to others, and a "Working" version of Matlab Desktop for when I am working..

Réponses (3)

Aurelien Queffurust
Aurelien Queffurust le 11 Oct 2011
To display MATLAB on a screen for a public , I run this function :
function largefonts(state)
% LARGEFONTS ON Turn on large fonts
% LARGEFONTS OFF Turn off large fonts
% LARGEFONTS Toggle large fonts
% LARGEFONTS FS Turn on large fonts, with font size FS.
% Get largefonts preferences
FS = getpref('LargeFonts');
if isempty(FS) % Create preferences if necessary
setpref('LargeFonts','State','Off');
end;
% Parse input arguments
if nargin==0 % Toggle state
state = lower(getpref('LargeFonts','State'));
switch state
case 'on'
state = 'off';
case 'off'
state = 'on';
end;
elseif ~isstr(state) % Specified font size. Turn on.
FontSize = state;
state = 'on'; % Turn on
else % Go to specified state
state= lower(state);
end;
if ~exist('FontSize','var')
FontSize = 16; % Default size for large fonts
end;
%%Toggle font sizes
switch state
case 'on'
% Big-
com.mathworks.services.FontPrefs.setCodeFont(java.awt.Font('Monospaced',java.awt.Font.BOLD,FontSize))
com.mathworks.services.FontPrefs.setTextFont(java.awt.Font('SansSerif',java.awt.Font.BOLD,FontSize))
setpref('LargeFonts','State','On');
case 'off'
% Small-
com.mathworks.services.FontPrefs.setCodeFont(java.awt.Font('Monospaced',java.awt.Font.PLAIN,10))
com.mathworks.services.FontPrefs.setTextFont(java.awt.Font('SansSerif',java.awt.Font.PLAIN,10))
setpref('LargeFonts','State','Off');
end;
  2 commentaires
Jan
Jan le 11 Oct 2011
Does this set the font property, such that you have to restart MATLAB to activate it?
juhisteri
juhisteri le 17 Juin 2021
Dear @Aurelien Queffurust, I like your code very much.

Connectez-vous pour commenter.


Jan
Jan le 11 Oct 2011
Font:
F = java.awt.Font('Arial', java.awt.Font.PLAIN, 16);
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)
cmdWinListener(iL).setFont(F);
break;
end
end
Layout:
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
desktop.restoreLayout('Command Window Only');
pause(0.1); % This might take some time
You can save the layout under an individual name. Note that the restoreLayout function is case-sensitive.
I'm going to add this to FEX: CmdWinTool. This tool can be used to create a lean desktop also.

Harry MacDowel
Harry MacDowel le 11 Oct 2011
You know what, Yair, I bet you gonna love this extraordinary File Exchange function called
cprintf
Till today it still amazes me the length the author of that file went to achieve that.
  1 commentaire
Jan
Jan le 11 Oct 2011
This will not help, because the OP wants to change the general appearence of all output.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by