Figure steals focus from parent app on update

1 view (last 30 days)
I have an app from which the user can run analysis functions which create some plots in new figure windows. These plots update during the analysis via changing the handle properties of the graphics objects.
My issue is that every time the figure updates it steals focus from the app. If you're working in another program entirely, it won't steal focus from that, but it will steal focus from any window which is part of the same Matlab session the app is running from.
This is a problem because I want the user to be able to still use the app (e.g. to pause the analysis) whilst the analysis is running, and it is irritating if the focus is lost whilst you're about to click a button, or if you're dragging the window to a different location on the screen.
I've seen one proposed solution to similar questions is to set the figure handle visibility to false. This is problematic for me, because I'm saving the figures to files, and if you save an figure with visibility=false, it will be still invisible still when you load it.
Can anyone suggest any solutions or workarounds for the above? Many thanks

Answers (1)

Image Analyst
Image Analyst on 9 Aug 2022
It's been a problem for years. It doesn't always seem to happen but when it does it's very annoying. I remember one time it wasn't happening but if I stopped at a breakpoint, then it would happen always after that.
The only workaround I know of is to have a "display" flag that you set in advance to not do any display/imaging/graphing functions.
Maybe search the forum for "steal focus" for prior discussions.
  1 Comment
Ben Mercer
Ben Mercer on 9 Aug 2022
Edited: Ben Mercer on 9 Aug 2022
Thanks. Yeah I have searched, and there are a few relavent posts. In most cases it seems you can stop from stealing focus by updating graphics objects via their handles. However, in this specific case, i.e. running code from within an app, then it still steals focus from the app even if you do it that way :-\
Unfortunately I can't not display the figures, since they are saved to file as part of the analysis.

Sign in to comment.


Find more on Graphics Object Properties 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!