• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

requestFocus() is not working across applications

 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



Thanks, I've tried, neither did it for me :-(

Any leads welcome.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Somehow requestFocus used to work in Java 1.1 (or 1.05) a decade ago



The focus subsytem was rewritten for JDK1.3.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic