今天逛論壇的時候發現一個很有意思的代碼 功能很好的,特地分享下;
代碼:
clc;
clear all;
h=figure;
jframe=getJFrame(gcf); %或者jframe=getJFrame(h);
jframe.setMaximized(1); %最大化figure
jframe.setMinimized(1); %最小化figure
jframe.setAlwaysOnTop(1); %將figure置頂
getJFrame文件在這:
function JFrame = getJFrame(hfig)
error(nargchk(1,1,nargin));
if ~ishandle(hfig) && ~isequal(get(hfig,'Type'),'figure')
error('The input argument must be a Figure handle.');
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.
JFrame = jfig.getRootPane.getParent();
if isequal(get(hfig,'Name'),'junziyang')
set(hfig,'Name',''); %Delete the temporary figure name
end