Reputation: 338
I've got a problem with requestInWindow
in Java where I need to focus on a textfield when its container becomes visible.
It works sometimes, but there are those times when a gui will run slowly because of os operations. For example if an antivirus is scanning the computer, programs will respond a bit slow.
Such is the case here. If the os is not doing anything heavy, requestInWindow
works fine, otherwise it does not.
So I want to know, is there a way to be absolutely dead sure that now JTextField
is visible, then we can kick in requestInWindow
at that moment. I tried a lot of things like SwingUtilities.invokeLater
and SwingWorker
.
In case you want know why I need this, look at a POS. The user does not have time to be moving around the mouse trying to focus on the field where they have to enter barcode or amount paid, all they need is to have the system do that for them, what they do is only hit the keypad.
Upvotes: 0
Views: 79
Reputation: 324207
Haven't tested this in all the situations that you describe, but if you want to specify the component with focus before the window is visible then you can try using the RequestFocusListener
approach from Dialog Focus.
I don't see why a slow running computer would cause a problem. As long as you make sure all your code is executing on the EDT is should work.
Upvotes: 1