MATLAB Answers


Command window is active but not in the foreground?

Asked by Sascha
on 22 May 2013

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 (R2013a)

Thanks, Sascha


Log in to comment.

1 Answer

Answer by Jan Simon
on 22 May 2013
Edited by Jan Simon
on 23 May 2013

This sounds like a bug. Perhaps this helps:


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)

Please try this again.

You can perform own experiments with:

desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
mainFrame = desktop.getMainFrame;

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.


@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.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!