Some JUCE apps don't get keyboard focus on start-up



Some JUCE applications don’t get keyboard focus on start-up. When double-clicking in explorer, the JUCE window will pop up behind the explorer window, and the taskbar icon will flash, but the window will not be focused. This is reproducible with the JUCE demo, but not with ProJucer.

It can be reproduced with the Hello World example by modifying the constructor of the HelloWorldWindow as follows:

// And show it!
setResizable(true, true);

It will no longer happen if you change the order:

// And show it!
setResizable(true, true);  // ← move down

But this will cause the window to appear twice (which gives a very noticeable stutter in the “fade in” animation, if you have those enabled).

Finally, this order works as expected

// And show it!
setResizable(true, true);  // ← move up

With the Demo app, moving those calls in that order in MainAppWindow::MainAppWindow() solves the problem. As to why, I have no idea. Anyone knows what’s happening here?


Application always starts minimized or behind all other windows
JUCE applications start on second plane in windows

setUsingNativeTitleBar will actually cause the Window to be recreated. Best to do that call before all other calls on the Window.


Also, in Xcode and VS2015, running a juce application in the debugger will sometimes not focus the app correctly on launch. Try launching it by hand and see if the problem goes away.


I’m double-clicking the executable in Windows explorer.