Note that there are some explanatory texts on larger screens.

plurals
  1. POjava swing: Focus lost on enter key event
    text
    copied!<p>I have a button in my dialog. After pressing enter key in that dilog, actions assigned to that button is getting called one by one.</p> <pre><code>public void buttonAction1() { } .... public void buttonAction2() { } </code></pre> <p>In my dialog I also have one text field on which focus lost event is listened. Whenever initially focus is inside that textfield, I click tab or using mouse I click on button, focus lost event is called and opens a popup. This pop-up helps to set the value inside text field. This value will be used by action called on button press.</p> <pre><code>public void focusLostAction() { } </code></pre> <p>Now the issue is that, when focus is inside text field and I press enter key, focus lost event is not getting called. So Pop-up is not getting opened and and proper values are not set inside that text field. but due to enter key event, action on that perticular button is getting called and this action is unable to find proper value inside text field.</p> <p>Inside the action method, which are called on enter key event, I have tried to set focus on button manually using:</p> <pre><code>public void buttonAction1() { button.requestFocusInWindow(); } public void buttonAction2() { // do the remaining task } </code></pre> <p>I also tried using, button.requestFocus;</p> <p>I was expecting that setting focus manually on that button will call loose focus from text field and focus lost event may get called (as this is implemented in separate swing worker thread). But it is not working. Please let me know, If you have faced this issue earlier and the solution for the same. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload