matlab figure 最大,最小,置顶

今天逛论坛的时候发现一个很有意思的代码 功能很好的,特地分享下;

代码:

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


 

你可能感兴趣的:(matlab figure 最大,最小,置顶)