Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame unable to requestFocus  RSS feed

 
Dan Kao
Greenhorn
Posts: 18
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

So I was trying to find out how to create a single-instance application, and I found this link which helped me a great bit.
The problem occurs when I try to get focus on the original frame.

Here's what I've tried (ApplicationInstanceManager and ApplicationInstanceListener are both from the above link)



When I open a second instance, the original frame should have grabbed focus, but all I see is the window icon flashing orange in the taskbar and nothing else.
I'm running it in Eclipse and using Windows 10.
Am I making a mistake (or is it perhaps the way I am trying to run it? I do have the taskbar flashing)

TIA
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may be confusing "get focus" (this component within the application becomes the one which is currently active) and "move to front" (this application, out of all applications running in Windows, becomes the one which is currently active).

However if you want the latter behaviour, I googled for "jframe move to front" and found a lot of complicated discussions about how it's impolite to force your application to the front in Windows and how on the other hand it might be okay to do that if it's what the user expects, and how various Windows operating systems disallow it or provide ways of permitting it... anyway I will let you go read those things if that's your goal, I don't have any particular expertise there.
 
Dan Kao
Greenhorn
Posts: 18
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, now I've found it (you're right, I was using the wrong term)

It seems that some operating systems don't allow the VM to place windows above those of native applications.
In the case of Windows, it only causes the taskbar to flicker.

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!