Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No more focus events in SWING

 
Michail Strelzow
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends!
I'm trying to fix a very strange focus bug for quite some time now, and I'm out of ideas.

It began with one user complaining, that from time to time, he could not enter text into textfields anymore after working with the application as usual.
When the problem occurred he called and I took a look at the application.
Nothing was focusable anymore. I could not enter any text by hand or select any written text out of textfields. When I pressed TAB for focus traversal, there was no active component.
It seemed like the entire focus subsystem was gone.
I activated the focus logging of awt like that:


and got results like this:

The application was recently upgraded to  jdk1.8.0_60, so I started digging around in some usual-suspect-files and got lucky.
swing.plaf.basic.BasicButtonListener.java was modified between jdk 6 and jdk 8. In the focusLost method the call order of .setPressed and .setArmed was switched causing the button to be triggered on a focusLost.

We had a validation on a focusLost implemented which opened a modal notification dialog. When the user entered invalid text and pressed a button, which also opened a modal dialog, two modal dialogues were visible at a time. This kind of killed the focus system. I don't know why thou.
I've switched the call order back to "normal" and the problem was gone.

Now another user is experiencing the same problem, with the patch already installed.
The application is quite complex and I can't figure out the use case this time.

Has anyone any idea what I can try to narrow it down? I've read a lot of posts and googled like hell, but most of the time people are complaining about single components not being focusable. But that's not the case here. The application works fine 99.9% of the time and when it doesn't nothing can get focused anymore.

Kind Regards!
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds possible that a modal dialog is displaying 'under' the application frame.  Make sure that any and all modal dialogs are correctly parented.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic