Focus lost when I drag in an external file


#1

How do I get the keyboard focus back to my Win App when it has been lost to a file explorer window?

setWantsKeyboardFocus(true);
&
grabKeyboardFocus();

Don’t work for me.
(Windows 10)


#2

Can you please try to explain what are you doing.


#3

Before you spend too long on this, bear in mind that most modern OSes deliberately prevent apps stealing the focus from a different process without the user actually clicking on your window.


#4

toFront(true); on the main component has worked for me.


#5

Are you dragging in or dragging out?

Anyway, I solved similar situations using the static method Process::makeForegroundProcess() (maybe in combination with Xenakios’ suggestion toFront())

HTH