Command window is active but not in the foreground?
Show older comments
Hi. Our version of matlab was recently updated in the institute, but I'm not sure, if this is related to my problem to be honest.
Before the update, typing something while a figure was the active window, brought the command window to the foreground & made it the active window to type in. Now, the command window is still the new active window, but remains in the background. So I have to alt-tab twice to see, what I write. Any solutions?
System is Linux mint, matlab version is 8.1.0.604 (R2013a)
Thanks, Sascha
Answers (1)
This sounds like a bug. Perhaps this helps:
[EDITED 2]
Although com.mathworks.mde.desk.MLDesktop.getInstance has toFront method, the mainFrame is required:
mainFrame = com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame;
set(mainFrame, 'WindowGainedFocusCallback', @(x,y) mainFrame.toFront);
The callback is executed in the base workspace, such that mainFrame must exist there also. This is nice for testing (if I found a new way to insert a bug in the code), but for a productive environment any user program will call clear all as far as the experiences in the forum show. So you need either the longer version:
set(com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame, ...
'WindowGainedFocusCallback', ...
@(x,y) com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.toFront);
or a dedicated function:
set(com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame, ...
'WindowGainedFocusCallback', @liftDesktop);
function liftDesktop(ObjectH, EventData)
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.toFront;
Please try this again.
You can perform own experiments with:
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
methods(desktop)
mainFrame = desktop.getMainFrame;
methods(mainFrame)
methods(..., '-full') shows details about the input arguments of the methods. Remember that these functions are not documented, but work since at least R2008a - except for your setup, where it obviously does not work directly. Therefore I recommend the version with the function and add exhaustive comments and a TRY CATCH error handling also.
10 Comments
Sascha
on 23 May 2013
Sorry, Sascha, I've cleaned the code to much. See [EDITED].
I could not test this under my Windows system, because here the command window is moved to the front already. But I tried desktop.toBack instead to get an extremely annoying behaviour, that activating the window moves it behind other windows. How cruel.
Sascha
on 23 May 2013
Jan
on 23 May 2013
Oh, Sacha, this is my fault. It is a problem that I've tried this at my Matlab computer without internet connection, and posted it 12 hours later on my internet computer. I dare to try it again. See [EDITED 2]
Sascha
on 26 Jun 2013
The error message means, that you either tried to create a function inside the command window or inside a script (an M-file, which does not start with "function"). Why does the function start in line 4? I dare to guess, that you set the ugly lines "clear all, close all, clc" on the top?
Is this function not called, when the command window gets the focus, or is it not successful?
Sascha
on 3 Jul 2013
Jan
on 3 Jul 2013
@Sascha: What happens if you add this line to the function liftDesktop:
disp(clock) % Just a dummy to check if this is called at all
Sascha
on 11 Jul 2013
Jan
on 11 Jul 2013
Then this means, that the WindowGainedFocusCallback callback is called regularily, but com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.toFront is damaged. Do you use the Java version shipped with Matlab or is the newest Java version used automatically like on Macs? I assume, that the Java call to bring the window to front is forwarded to a system call, such that an update of your window manager could be useful also. I could offer a system call, which bring windows to front under Windows, but I do not know how to do this under Linux.
But in any case I think that contacting the technical support might be useful, after you and me have tried all more or less obvious workarounds.
Categories
Find more on Startup and Shutdown 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!