Position of Not-visible figure is WRONG (two monitors bug?)

6 views (last 30 days)
If I create a figure and maximize it, I got sizes fitting my second monitor:
fig = figure('Menu','none','ToolBar','none','WindowState','maximized','Visible','on');
>> fig.Position
ans =
1.0e+03 *
0.0010 0.0490 1.2800 0.6493
But if I create a not visibile figure, I got a wrong position:
fig = figure('Menu','none','ToolBar','none','WindowState','maximized','Visible','off');
>> fig.Position
ans =
360 198 560 420
Moreover, if I change the visible property to "ON", Matlab at first shows me the same wrong position (even if the figure is indeed maximized, I can see it on the screen):
fig.Visible='on'
but when I click on "show all properties", it shows the right position:
fig.Position
ans =
1.0e+03 *
0.0010 0.0490 1.2800 0.6493
How can I solve this? I need it to properly define some sizes in my App (app designer).
For now, I create a figure, store the position and close it. But I would like the user didn't see an empty figure during the process.
Thank you
  1 Comment
dpb
dpb on 11 May 2022
Again, you can avoid that by a selective workaround of a set of coordinates that you know are going to be in the visible range...depends upon which effect you think the lesser evil -- the temporary figure flicker or not being exactly where you want it.
I'd think it possible to figure out an algorithm about where your position is that you could compute a satisfactory set of coordinates from the data that are available.

Sign in to comment.

Accepted Answer

dpb
dpb on 10 May 2022
I deal with it by having a usersettings structure saved as a .mat file that contains all the stuff to restore from the user's last session including the last position of figures where the user left them. The startup function reloads all those so the figure will be recreated where the user last left it. If the file doesn't exist, then there are some system defaults that are reasonable for the number/size of monitor(s).
You can discover the number and size of monitors at the time your app starts by querying the root properties of the graphics environment. See the doc section titled "Root Properties" under Graphics Object Properties
With that data, you can set reasonable bounds based on the user's environment and not be dependent upon the defaults as your present method is.
  5 Comments
dpb
dpb on 12 May 2022
Yeah, Walter, I didn't even begin to touch that level of detail -- in my environment at least, it's good enough to have the figure be on the screen; ime the user will always end up tweaking/moving stuff around anyways, no matter how finely-tuned the developer thinks they've made it.
Sometimes, there is no practical alternative but "perfect enough"...

Sign in to comment.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!

Translated by