Normalize app designer window position (2024)

65 views (last 30 days)

Show older comments

Brandon Campanile on 1 Dec 2018

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position

Commented: Marten Claes on 10 May 2024 at 16:57

Open in MATLAB Online

I have an application I made in app designer that has the line app.UIFigure.WindowState = 'maximized'. The UIFigure has a default position of [1 1 1920 1080] and fits to my screen very nicely and maximizes very well. However, it's only working for my display; on anyone elses it does not scale correctly. The matlab application I am using is located here. The "normalized" property is not yet supported in app designer so I have to use the pixel units. Whenever I change the size of the UIFigure programmatically it does not resize the children (yes I have resize children on). I've tried the following:

d=get(0,'screensize');

app.UIFigure.Position = [1 1 d(3) d(2)];

However, this isn't changing the size of the children recursively. I even tried scaling it like this:

d = get(0,'screensize');

app.UIFigure.Position = [1 1 d(3)*app.UIFigure.Position(3)/1920 d(4)*app.UIFigure.Position(4)/1080];

The above works for some elements (not UIFigure), but I have too many to do that for each one. I also tried making a recursive function. I dont remember exactly, but it was something like this:

d = get(0,'screensize');

updatePosition(app.UIFigure)

function updatePosition(R)

if ~isempty(R.Children)

R.Children.Position = [1 1 d(3)*R.Children.Position(3)/1920 d(4)*R.Children.Position(4)/1080];

updatePosition(R.Children)

end

end

Nothing is working. App designer needs some serious TLC. Does anybody know of a way to get the app to size appropriately for different screen sizes and resolutions (short of a startup fnc that changes the position of every single element)?

1 Comment

Show -1 older commentsHide -1 older comments

Chris Portal on 3 Dec 2018

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_645366

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_645366

Do you have screenshots that shows what it looks like on your display vs someone elses, just to understand what you mean by “does not scale correctly”?

Sign in to comment.

Sign in to answer this question.

Answers (5)

Jorge Barrasa Fano on 6 Aug 2019

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_386380

The line:

movegui(app.UIFigure,"center");

at the beginning of startupFcn works fine for me. No need to do pause() and it avoids playing with window coordinates.

1 Comment

Show -1 older commentsHide -1 older comments

Andrew Diamond on 27 Mar 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_816561

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_816561

Edited: Andrew Diamond on 27 Mar 2020

This doesn't rescale the children for me. On a display smaller than the application size, It will move the app and seems to resize the figure to fit but not the children. I have whole gui elements that are simply not available because of this (they get chopped off in the now smaller figure). Resizing the window manually afterwards doesn't do anything to help. The FigureSizeChanged callback does not get called.

It does seem that if I stop in the debugger in the startufcn it will do it but I tried to emulate that with a pause(5) and a drawnow but that didn't work. I guess I could set up a timer to try and resize in a few seconds but it's pretty nasty

Sign in to comment.

Scott Guillaudeu on 22 Jul 2019

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_384271

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_384271

In startupFcn, try pause(2) before setting app.UIFigure.Position. It's ugly and I don't know exactly why it works, but It seems to take a while to layout the figure the first time and it will only resize all the children after it's done the first layout.

This works for me on a Mac, but I haven't tried any other OSes.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Skander Ayoub on 25 Nov 2021

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_840084

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_840084

Open in MATLAB Online

Try this:

function startupFcn(app)

app.UIFigure.Visible = 'off';

movegui(app.UIFigure,"center")

app.UIFigure.Visible = 'on';

end

2 Comments

Show NoneHide None

Mike McCullough on 25 Apr 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_3143891

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_3143891

Really appreciate this set of commands!

I searched google for 1 hour before finding this...

Marten Claes on 10 May 2024 at 16:57

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_3157806

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#comment_3157806

Is there any way that function startupFcn(app) can be called upon clicking run in appdesigner?

Sign in to comment.

Mekiedje Jöel on 21 Jan 2019

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_357390

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_357390

Hello, i just have the same problem. Have you solved the problem ?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

p su on 2 Jan 2023

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_1139742

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/433152-normalize-app-designer-window-position#answer_1139742

Open in MATLAB Online

All elemetns in the position vector have to be resized (including the x and y).

app.UIFigure.Position = [10, 20, 200, 100];

d = get(0, 'screensize'); % [1, 1, 1920, 1200]

ratio = [d(3)/app.UIFigure.Position(3), d(4)/app.UIFigure.Position(4)];

app.UIFigure.WindowState = 'maximized';

app.Children.Position = app.Children.Position .* [ratio, ratio]; % [x, y, w, h] .* [ratio_w, ratio_h, ratio_w, ratio_h]

I do find out that the above resizing is not perfect, since the ratio was calculated based on the whole screen size, which will include the heights of task bar and title bar and miscalculate the ratio. In order to fixe it, use the maximized UIFigure position instead.

app.UIFigure = uifigure('Visible', 'on');

app.UIFigure.Position = [10, 20, 200, 100];

oldPos = app.UIFigure.Position;

app.UIFigure.WindowState = 'maximized';

drawnow; % Force to draw the uifigure first

newPos = get(app.UIFigure, 'Position'); % [1, 41, 1920, 1137]

ratio = [newPos(3)/oldPos(3), newPos(4)/oldPos(4)];

app.Children.Position = app.Children.Position .* [ratio, ratio]; % [x, y, w, h] .* [ratio_w, ratio_h, ratio_w, ratio_h]

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsGraphics ObjectsInteractive Control and Callbacks

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

  • gui
  • matlab gui
  • app designer
  • figure

Products

  • MATLAB

Release

R2018b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Normalize app designer window position (11)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Normalize app designer window position (2024)

References

Top Articles
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 5746

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.