requestFocus() is not working across applications

What's wrong with this code? I get focusLost() events all right, and when I requestFocus(), I get focusGained().. except it is NOT gained, my caret is still in Notepad! How do I get my caret out of there?

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 157

posted May 04, 2010 10:19:23

0

Update. By adding f.requestFocusInWindow(), I now get TWO carets! One in f, and the other, in my Notepad. The one in Notepad, undoubtedly, native; that's where the keyboard input goes.

The focus methods are only used to change focus within components on a Window.

I have no idea what Notepad has to do with this. If you have notepad open in a window and then start your Java appliaction and show a dialog, then the dialog should have focus by default.

It looks like you are trying to prevent your dialog from losing focus if you then click on Notepad. This is a bad design you should never prevent a user from using another application.

There are methods like alwaysOnTop() which will make sure your dialog is always visible. Or there might be times you want to use the toFront() method to make the dialog behave like a notification popup.

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 157

posted May 04, 2010 11:01:27

0

Rob Camick wrote:I have no idea what Notepad

Ah, but you do.

It looks like you are trying to prevent your dialog from losing focus if you then click on Notepad.

Exactly.

This is a bad design you should never prevent a user from using another application.

Might be more prudent to ask WHY I need this design, before rushing with a judgment. I am simulating an ATM machine for very computer-illiterate users who only have numeric keypad anyway, and if any 3rd party software pops up with a dialog, they currently have no recourse other than rebooting.

There are methods like alwaysOnTop() which will make sure your dialog is always visible. Or there might be times you want to use the toFront() method to make the dialog behave like a notification popup.

Jane Jukowsky wrote:I am simulating an ATM machine for very computer-illiterate users who only have numeric keypad anyway, and if any 3rd party software pops up with a dialog, they currently have no recourse other than rebooting.

As far as I know this is generally solved by configuring the operating system to not allow any other software except your application. (I think it's called "kiosk" mode.) As Rob suggests, trying to prevent other applications from taking the focus is directly opposed to what the operating system naturally does, so you'll find the operating system doesn't make it easy for any application to do it.

So you are better off trying to manage the environment rather than trying to hack it.

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2261

8

posted May 04, 2010 12:40:31

0

Might be more prudent to ask WHY I need this design, before rushing with a judgment.

Actually it would be more prudent for you to state the actual requirement so we don't have to guess exactly what it is you are trying to do.

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 157

posted May 04, 2010 12:50:45

0

Thank you Paul, I did not know about kiosk mode. It does not appear Windows supports that natively; a free Microsoft utility SteadyState seems to, but it does a lot more, such as hard drive protection, so I'd much rather just kept focus with a 1-liner if I could. Somehow requestFocus used to work in Java 1.1 (or 1.05) a decade ago, and somehow it stopped working, even in java.awt.Dialog, hmm.

So.. sorry about the offtopic, but are there superior alternatives to SteadyState, as far as kiosks go?