声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

声振论坛 展示 基础理论 查看内容

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

2012-10-19 11:02| 发布者: aspen| 查看: 836| 评论: 0|原作者: ChaChing|来自: 振动论坛

摘要: 在这里http://forum.simwe.com/viewthread.php?tid=880867page=1#pid1824705 看到这个, 觉得好玩, 转来与大家共同欣赏! function chgicon(hfig,iconfile) %CHGICON changes the Figure HFIG's icon to the icon ...
在这里http://forum.simwe.com/viewthread.php?tid=880867&page=1#pid1824705
看到这个, 觉得好玩, 转来与大家共同欣赏!

  1. function chgicon(hfig,iconfile)
  2. %CHGICON changes the Figure HFIG's icon to the icon specified by ICONFILE
  3. % HFIG must be a figure handle.
  4. % ICONFILE is a string specifies the path to an imagefile.
  5. %
  6. %WARNING:
  7. % Changing the matlab icon violate the mathworks license. THis function can
  8. % only be used for study purpose. Please delete it within 24 hours.
  9. %
  10. % Author: junziyang (simwer@126.com)
  11. % Ver.1.0
  12. % 2009-05-20
  13. error(nargchk(2,2,nargin));
  14. if ~ishandle(hfig) && ~isequal(get(hfig,'Type'),'figure')
  15. error('The first input argument must be a Figure handle.');
  16. end
  17. if ~ischar(iconfile) || ~exist(iconfile,'file')
  18. error('Icon file name is not input properly.');
  19. end
  20. mde = com.mathworks.mde.desk.MLDesktop.getInstance;
  21. if isequal(get(hfig,'NumberTitle'),'off') && isempty(get(hfig,'Name'))
  22. figTag = 'junziyang'; %Name the figure temporarily
  23. set(hfig,'Name',figTag);
  24. elseif isequal(get(hfig,'NumberTitle'),'on') && isempty(get(hfig,'Name'))
  25. figTag = ['Figure ',num2str(hfig)];
  26. elseif isequal(get(hfig,'NumberTitle'),'off') && ~isempty(get(hfig,'Name'))
  27. figTag = get(hfig,'Name');
  28. else
  29. figTag = ['Figure ',num2str(hfig),': ',get(hfig,'Name')];
  30. end
  31. drawnow %Update figure window
  32. jfig = mde.getClient(figTag); %Get the underlying JAVA object of the figure.
  33. jfig.setClientIcon(javax.swing.ImageIcon(iconfile));
  34. if isequal(get(hfig,'Name'),'junziyang')
  35. set(hfig,'Name',''); %Delete the temporary figure name
  36. end
复制代码


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

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

最新评论

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-24 19:01 , Processed in 0.046676 second(s), 15 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部