views:

499

answers:

3
+1  A: 

I don't know about global modal, but here's an idea.

  1. Take the screenshot of the desktop.
  2. Go full screen.
  3. Pop up your dialog.

Since the desktop is fake screenshot, you can ignore any attempt to click into it.

Full screen sample:

private void toggleFullScreenWindow() {
  GraphicsEnvironment graphicsEnvironment
 = GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice graphicsDevice
 = graphicsEnvironment.getDefaultScreenDevice();
  if(graphicsDevice.getFullScreenWindow()==null) {
 dialog.dispose(); //destroy the native resources
 dialog.setUndecorated(true);
 dialog.setVisible(true); //rebuilding the native resources
 graphicsDevice.setFullScreenWindow(dialog);
  }else{
 graphicsDevice.setFullScreenWindow(null);
 dialog.dispose();
 dialog.setUndecorated(false);
 dialog.setVisible(true);
 dialog.repaint();
  }
  requestFocusInWindow();
}

FYI: Full-Screen Exclusive Mode API.

eed3si9n
Doesn't work on Mac.
Daniel Spiewak
mhhh... could be.. could be.. I'll give it a try and see if there is a blink. Thanks.
OscarRyz
Why would you deceive your users like that?
Matt Green
+2  A: 

Hello,

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.

Louis Jacomet
My mistake. I didnt put the initialization code. Yeap I started with JFrame then google a while and switch to JDialog. The thing here is not to block the appliation windows but the whole OS windows.
OscarRyz
+2  A: 

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.

Daniel Spiewak
Great "comment" now do you have an "answer"?
OscarRyz