Command window is active but not in the foreground?

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)

Jan
Jan on 22 May 2013
Edited: Jan on 23 May 2013
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

Hi.
Unfortunately, it does not.
Errormessage is:
The class "desktop" is undefined. Perhaps Java is not running.
Jan
Jan on 23 May 2013
Edited: Jan 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.
heh, so you found/showed me something nice for playing a prank on colleagues!
Sadly, also the edited code does not work for me. Errormessage:
No method 'toFront' with matching signature found for class 'com.mathworks.mde.desk.MLDesktop'.
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]
Hey.
Somehow this topic got erased from my to do list. Unfortunately the above code is so much beyond my knowledge, all I could do was a "copy paste trial". Unfortunately again, the code does not produce the desired outcome- the command window is active but keeps itself hiding behind the figures. The function-version even produces an error:
Error: File: MatlabCommandWindowToFront.m Line: 4 Column: 1
Function definitions are not permitted in this context.
Jan
Jan on 26 Jun 2013
Edited: Jan 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?
Ah, I see. I implemented all this into the function:
set(com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame, ...
'WindowGainedFocusCallback', @liftDesktop);
function liftDesktop(ObjectH, EventData)
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.toFront;
Now with only saving the latter 2 rows, and copying the first ones in the command window, there is no error anymore. Unfortunately, theres also no visible effect on the problem.
Btw: I really appreciated your efforts! :)
@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
the normal "clock" output is displayed then.
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.

Sign in to comment.

Categories

Asked:

on 22 May 2013

Community Treasure Hunt

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

Start Hunting!