Swing app global modal

Simple question:

Can a swing frame be completely modal ( block all others windows ) ?

I tried the following, but I can still click on other apps windows ( like this browser )

JDialog myDialog  = .... 

Plase paste some code if this is possible.


JFrame is not designed to be modal. Use JDialog for it, but you will loose some JFrame functionality doing so. If you can't live with the loss, you have to block the EventQueue and replace it with your own to only accept events from the blocking one.

See Creating Modal Internal Frames for an explanation using internal frames that should be applicable to JFrame also.

Edit: Oups, my answer seems a bit off, since your code example shows you are already using a Dialog subclass for this.

Dialogs are not meant to be globally modal. Every modern OS strongly discourages global modality in its HIG, and they may even have deprecated the functionality (as indicated by the fact that you can't get it to work). Your app should never steal events from the entire system; that's not only bad design, it's near-criminal in my book.

Ignoring the fact that most people like to multi-task between several apps, what about the scenario where you open a globally modal dialog and then your application freezes? Ctrl+Alt+Del should work on Windows to kill the app, but I'm not sure about Cmd+Opt+Escape on Mac with a globally modal dialog (does Cocoa even have global modality?). None of the Linux platforms have any nice way of killing apps which have taken over complete control of the UI as you are suggesting (you would have to kill X11 completely and start a new instance from scratch).

My answer: find another way. I don't care what your client is asking for, they don't want this.

Need Your Help

How to ensure atomic reads and atomic writes?

java atomic

I want atomic reads and atomic writes to Integer (not int) and others as follows:

Like button on each page

asp.net facebook dynamic like

I have a like button on my main page (master page in asp.net).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.