Daniel Hiller

Geek, programmer, father
I'm a software engineer with more than 20 years of work experience.
I strive to create software that is useful for people so they can do stuff that matters.

NetTool, a great HTTP request handling tool
All posts
Warum ich TDD liebe

Modal JDialogs


java swing 

Recently our customers experienced problems running our software after updating to JRE6U12. In detail on Windows XP the desktop application would hang directly after connecting to the database. Downgrading the RE to U11 fixed the problem so we first thought it was a bug in the JRE.

Since google investigation did not bring any results except this we were convinced it should be our fault. After several hours of checking swing calls outside of the evnt dispatch thread, checking for undisposed dialogs and hunting down modal dialogs we found the following two statements.


Do you see the problem? Neither did we at first. And since the code had worked before we did not think the order of these two statements would be the problem.

In fact it does not make much sense to set a dialog to modal after making it visible, but still these two lines were the cause of the main window losing focus, not reacting to input events any more, and for the user being unable to reactivate the main window. To the user this looks like a freeze of the application.

So now, after several hours of debugging, we know that we must call setVisible(true) after setModal(true)!

Related posts:

NetTool, a great HTTP request handling tool
All posts
Warum ich TDD liebe

Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Last update on 2023-11-29. Built by dhiller using Atom (editor), Jekyll (site builder), OneDark vivid (syntax highlighting theme), Webjeda (related posts), Disqus (discussions), Github Pages (hosting), Cloudflare (DNS).