MATLAB does not have any official way of doing this. This difference that you're seeing is due to a difference in the default uicontrol
and uipanel
BackgroundColor
property between releases. I have a script below that can actually load in a .fig
file (created with GUIDE or otherwise) and swap out the BackgroundColors
of uicontrol
or uipanel
objects with the current default background color. It then re-saves the .fig
file while maintaining a backup of the original.
function varargout = updatebgcolor(figfile)
% updatebgcolor - Updates the uicontrol background colors
%
% USAGE:
% updatebgcolor(figfile)
data = load(figfile, '-mat');
% Types of controls to update
types = {'uicontrol', 'uipanel'};
% Get the current default background color
bgcolor = get(0, 'DefaultUIControlBackgroundColor');
% Switch out all of the background colors
data2 = updateBackgroundColor(data, types, bgcolor);
% Resave the .fig file at the original location
movefile(figfile, [figfile, '.bkup']);
save(figfile, '-struct', 'data2')
if nargout; varargout = {data2}; end
end
function S = updateBackgroundColor(S, types, bgcolor)
% If this is not a struct, ignore it
if ~isstruct(S); return; end
% Handle when we have an array of structures
% (call this function on each one)
if numel(S) > 1
S = arrayfun(@(s)updateBackgroundColor(s, types, bgcolor), S);
return
end
% If this is a type we want to check and it has a backgroundcolor
% specified, then update the stored value
if isfield(S, 'type') && isfield(S, 'BackgroundColor') && ...
ismember(S.type, types)
S.BackgroundColor = bgcolor;
end
% Process all other fields of the structure recursively
fields = fieldnames(S);
for k = 1:numel(fields)
S.(fields{k}) = updateBackgroundColor(S.(fields{k}), types, bgcolor);
end
end