How to prevent resizing larger than a certain amount

조회 수: 2 (최근 30일)
Chris Herrera
Chris Herrera 2015년 7월 29일
댓글: Chris Herrera 2015년 7월 29일
Hi All, I have a GUI I make programatically and the size it starts at is full screen (i.e. in the figure(property,value...'Position',get(0,'screensize'),...)
I want to know if there is a way to prevent users from resizing it larger but still be able to resize it smaller. Apart from the Figure size, everything is in normalized units. I have a dual monitor set up (laptop with external monitor) and the figure first shows at the full screen of my laptop window. I want to be able to resize it smaller but not any larger than it's starting size (laptop full screen size).
I tried setting the figure resize function as:
function resizeMainFigure(hObject,eventdata)
% -------
% Prevent oversizing the window
% -------
newPosition = get(mainFigure,'position');
if newPosition(3) > scrsz(3); newPosition(3) = scrsz(3); end
if newPosition(4) > scrsz(4); newPosition(4) = scrsz(4); end
set(mainFigure, 'Position', newPosition);
end
Where scrsz = get(0,'screensize'); (it spans multiple functions) and mainFigure is the variable storing the figure handle. I'm using 2015A

답변 (1개)

Jan
Jan 2015년 7월 29일
This does not work with HG2 yet, but I'll fix this today.
  댓글 수: 2
Chris Herrera
Chris Herrera 2015년 7월 29일
Thank you both for the link. It looks like exactly what I need. What is HG2 if you don't mind?
Chris Herrera
Chris Herrera 2015년 7월 29일
Hi I got this error when using LimitSizeFig.
Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks web site. > In LimitSizeFig (line 97) No appropriate method, property, or field 'fFigureClient' for class 'com.mathworks.hg.peer.HG2FigurePeer'. Error in LimitSizeFig (line 101) jClient = jFrame.fFigureClient;
Code used to produce error:
scrsz = get(0,'ScreenSize');
figureSize = [scrsz(1)+5,scrsz(2)+5,scrsz(3)-10,scrsz(4)-10];
mainFigure = figure('Visible','off','Position',figureSize,'Name','CeleST: Video Processing - Choose the videos to process, define the swimming zones, launch the processing','numbertitle','off', 'menubar', 'none', 'resizefcn', @resizeMainFigure);
LimitSizeFig(mainFigure, 'max', [figureSize(3) figureSize(4)]);
I'm running 2015A

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by