0

I have a Java-application that needs to be brought to the foreground and you have to be able to press keys.

I thought about a timer. It's like you can play a game and press some keys and the timer will count.

I've got this

@Override
public void focusLost(FocusEvent arg0) {
    System.out.println("Lost");
    TimerFrame.toFront();
    TimerFrame.requestFocus();
}

It's flashing in the taskbar and not focused all the time.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user3817405
  • 1
  • 1
  • 1

1 Answers1

1

You can't do this reliably, because its considered malicious behavior by the window manager.

There were all kinds of crapwares doing just that, so at some point (starting with WindowsXP IIRC) some additional checks were added to the window system to prevent popups stealing the input focus.

While you may find a way around the current restrictions in the window manager, you should think hard if that "feature" will accomplish anything other than annoying users.

Here's the perfect example of that kind: Frame always on top of my program only

Community
  • 1
  • 1
Durandal
  • 19,919
  • 4
  • 36
  • 70