java gui 更换图标_Matlab GUI 如何修改对话框的左上角图标

本文介绍了一种在MATLAB GUI中修改对话框左上角图标的JAVA方法,包括提供了一个名为chgicon的函数,该函数接受一个图形句柄和图标文件路径作为输入,以更改MATLAB图形窗口的图标。警告指出,从R2009a版本开始,使用Figure的JavaFrame属性会过时,但作者通过研究找到了新的方法来实现这一功能。
摘要由CSDN通过智能技术生成

我也在看这个问题,这个帖子不错,可以看看,可以我不能复制网址。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值