ChaChing 发表于 2009-11-18 21:06

【转贴】更改Figure图标的新方法

在这里http://forum.simwe.com/viewthread.php?tid=880867&page=1#pid1824705
看到这个, 觉得好玩, 转来与大家共同欣赏!
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 violate the mathworks license. 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',''); %Delete the temporary figure name
end


月初即想转贴, 并询问友网是否允许转贴!
已经版主同意, 但想若经楼主同意好像更尊重些, 一等一忙竟给忘记了!
刚在中文又看到http://www_ilovematlab_cn/viewthread.php?tid=57132&page=1#pid532336 (change "_" to ".")
不知是否为原创者, 但肯定是旧版!
怕再次忘记, 先贴了

[ 本帖最后由 ChaChing 于 2010-5-21 18:18 编辑 ]

pzfs1016 发表于 2012-2-9 16:18

感谢楼主!

suiyidodo 发表于 2012-3-24 00:46

谢谢 楼主啊

machreehappy 发表于 2012-9-25 12:14

{:{10}:}{:{10}:}学习啦

mni987654321 发表于 2012-10-22 19:18

这都可以啊

竺郁 发表于 2013-8-31 14:13

这是什么,怎么我运行不出来??
页: [1]
查看完整版本: 【转贴】更改Figure图标的新方法