简体   繁体   中英

Java requestInWindow sometimes does not work

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM