我也在看这个问题,这个帖子不错,可以看看,可以我不能复制网址。
Figure的JavaFrame属性实现的。遗憾的是,从R2009a开始,使用这个函数时开始出现如下警告:
Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks Web site.
也就是说,在以后的版本中Figure的JavaFrame属性就没法用了。以前写的那个changeicon函数也会随之失灵了。
修改Figure图标的方法不止一种,simwe论坛里就可以找到几个方案。但JAVA方法相对来说简单一些,可以写成MATLAB中的函数来方便的调用,所以本人还是更喜欢这种方法。MATLAB的所有界面是用JAVA实现的,理论上来说,界面上的所有东西都是可以通过JAVA来修改的!!虽然JavaFrame被封掉了,但肯定还有其他方法来改Figure的图标。经过一番研究,终于找到了这样一种方法。全部代码如下:
function chgicon(hfig,iconfile)
%CHGICON changes the Figure HFIG's icon to the icon specified by ICONFILE
% HFIG must be a figure handle.
% ICONFILE is a string specifies the path to an imagefile.
%
%WARNING:
% Changing the MATLAB icon violates Mathworks license agreement. THis function can
% only be used for study purpose. Please delete it within 24 hours.
%
% Author: junziyang (simwer@126.com)
% Ver.1.0
% 2009-05-20
error(nargchk(2,2,nargin));
if ~ishandle(hfig) && ~isequal(get(hfig,'Type'),'figure')
error('The first input argument must be a Figure handle.');
end
if ~ischar(iconfile) || ~exist(iconfile,'file')
error('Icon file name is not input properly.');
end
mde = com.mathworks.mde.desk.MLDesktop.getInstance;
if isequal(get(hfig,'NumberTitle'),'off') && isempty(get(hfig,'Name'))
figTag = 'junziyang'; %Name the figure temporarily
set(hfig,'Name',figTag);
elseif isequal(get(hfig,'NumberTitle'),'on') && isempty(get(hfig,'Name'))
figTag = ['Figure ',num2str(hfig)];
elseif isequal(get(hfig,'NumberTitle'),'off') && ~isempty(get(hfig,'Name'))
figTag = get(hfig,'Name');
else
figTag = ['Figure ',num2str(hfig),': ',get(hfig,'Name')];
end
drawnow %Update figure window
jfig = mde.getClient(figTag); %Get the underlying JAVA object of the figure.
jfig.setClientIcon(javax.swing.ImageIcon(iconfile));
if isequal(get(hfig,'Name'),'junziyang')
set(hfig,'Name',''); �lete the temporary figure name
end