How do I make an App window full screen programmatically in MATLAB?

I have a Matlab app, and I would like that it starts always maximized without using the mouse to maximize the figure window.

댓글 수: 7

It's been answered here .
The answer is for a GUI figure, not for a Matlab app, I start today with Matlab app, so I'm new on this
Eyal Tal
Eyal Tal 2018년 11월 30일
편집: Eyal Tal 2018년 12월 3일
Use property:
app.<your app name>UIFigure.WindowState = 'maximized';
I tried it in App Designer today in the startup callback, and it doesn't seem to work.
I refined my answer, it works for me.
Image Analyst
Image Analyst 2018년 12월 4일
편집: Image Analyst 2018년 12월 4일
I called tech support today, because it seemed to maximize if I set a break point there, and not maximize if there was no breakpoint there. They never did figure that out, but we did figure out that you need to call drawnow before you set the WindowState to 'maximized'. If you do that, it does move the controls to full screen, though their position is goofy. It's not just a magnified version of the smaller figure you had designed. The controls stay the same size (don't enlarge) and it has some nonsensical (to me anyway) rules for positioning the controls to their new locations on the full screen.
why do everyone of them answer for maximizing a figure window, when the question is maximising the window or for the fact any model or application window in maximised mode, or to the set window size.

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

답변 (2개)

Marek Svoboda
Marek Svoboda 2019년 8월 18일
편집: Marek Svoboda 2019년 8월 18일
OK, so the information is all here but needs to be peaced together. I suggest a new complete answer, which is:
Left click "app.UIFigure" in the Component Browser (right column) -> "Callbacks" -> "Add startupFcn callback" -> enter the following code:
function startupFcn(app)
drawnow;
app.UIFigure.WindowState = 'maximized';
end
This opens the window in smaller size on startup and subsequently resizes it, adjusting the content appropriately. For the resizing of the contents to really work properly, I higly recommend using an "Auto-Reflow" (i.e. responsive) layout of your app. If you leave out drawnow, the app opens fullscreen right away, but it does not adjust the contents.

댓글 수: 5

Works perfectly! Thanks!
Thank you so much!! Good job!!?
Please suggest the code for MATLAB R2016a to maximize the all components inside UIFigure because above code gives error in matlab R2016a
It doesn't make sense to maximize individual components/controls/widgets sitting on a figure. It only makes sense to maximize a whole figure/window.
If you want to maximize a figure window, first get the handle to it, then set the WindowState property to 'maximized':
g = gcf; % Get handle to the current (last) figure
g.WindowState = 'maximized'
@Krutik Gujarathi just add the following line in the OutputFcn:
maximize(hObject);
IMPORTANT: All the objects will need resizing and they mess up the layout when used on different windows. So I'd suggest to do the following:
  1. Double click on the object (Pushbutton, Radiobutton etc.)
  2. Change the "Units" to "normalized"
  3. Repeat for every object in your UIfigure

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

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 8월 17일

댓글:

2024년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by