Close application from task-bar when a modal dialog is opened - java

When a modal dialog is opened, is there any way to allow user close a JFrame by clicking Close on task-bar icon? I see that even if the dialog is orphan or a child of another frame, it still blocks the Close action.

It depends on the native OS you're running on, I don't know of any that do allow you to.
Here is a MSDN listing on it :
http://msdn.microsoft.com/en-us/library/aa969773.aspx
A modal dialog box is displayed by a function when the function needs
additional data from a user to continue. Because the function depends
on the modal dialog box to gather data, the modal dialog box also
prevents a user from activating other windows in the application while
it remains open.

Related

Non-modal JDialog unable to gain focus

I am facing a very strange issue: I have a non-modal JDialog in a very complex Swing application. There is a situation where another (modal) dialog opens above the non-modal one. After closing the modal dialog, it is no longer possible to click on anything in the non-modal dialog. After adding a FocusListener I realized that the focus cannot be gained. I am not able to click on any button or slider inside the dialog, nor does it react if I click on its title bar. Whenever I am trying to do so, an OS sound clip is being played which you would normally expect to hear when trying to click on a component while another modal component is still visible. But it's not.
Fun fact: the bevavior goes away when another modal window of any kind is being opened and closed again! After that, the non-modal dialog re-gains the focus.
I apologize for not being able to post the code here, as dozens of classes are involved to reproduce this. But if maybe anyone has ever come across a similar issue or behavior and knows where it comes from, it would be great if you shared your knowledge about how to overcome it.
Thanks in advance!

Java applet destroy() with showConfirmDialog

I'm doing some bug fixing on an old applet, but I'm running into issues with applets destroy() being called while there is a confirm dialog open (JOptionPane.showConfirmDialog). Basically, If there is a dialog box open, and the browser window is closed, the dialog box stays open, and the applets keep running in the background (not in a browser window). Is there a way to close all the dialog boxes and ensure that all applets are destroyed when the browser window is closed?
EDIT: ok, to clarify, this confirm dialog is being opened in a thread that the applet starts. However, it has the instance of the applet that started it, and the confirm dialog is being started with JOptionPane.showConfirmDialog(applet_instance, ...) This should mean that the user is unable to access the browser while the dialog is up. However, I can still close the window behind the dialog, and this kills the applet, but not the thread that opened the dialog. How would I go about killing all the threads when the window is closed, or how do I actually stop the user from closing the window without acknowledging the dialog first?
EDIT 2: I just tried to make the dialog in the applet itself, at the end of the start() method. This results in a dialog right when the applet loads, but I can still close the browser window behind the dialog and the dialog remains...

ModalDialog blocking in java

I have a long task which is running and I am popping up a modaldialog with MainUI.modalDialog.setVisible(true); which has a ProgressBar. However I do observe that it is blocking the process. How do I popup the Dialog without blocking whatever is running in my frame?
That is the modal dialogs behavior. The options are that you either don't display it as modal or you display it in a separate thread.
You should whatever is running in your frame into another Thread, in case it is not GUI code. Also you could run the modal dialog in a separate GUI thread.
http://en.wikipedia.org/wiki/Modal_window
"In user interface design, a modal window is a child window that requires users to interact with it before they can return to operating the parent application, thus preventing the workflow on the application main window. Modal windows are often called heavy windows or modal dialogs because the window is often used to display a dialog box."
Solution: Do not use a Modal Window.

How can an applet be modal and keep IE9 window from closing?

I have a JAVA applet that brings up an application modal dialog. The problem I am having is that the user can close the browser (or tab) and the dialog will remain up. If you click on the IE9 window area or menu bar the dialog appears modal, but when you click on the tabs or the window's "x" button IE9 is not modal to the dialog. I have tried various forms of modality and none seem to make the entire window and dialog modal. I tried using a window listener in the applet, but it doesn't seem to get the closing message. If you close the windows this way, the java process does not properly shut down and you have to kill it via the task manager. I don't remember this happening with IE8. Is there any way to make the entire IE9 window and my dialog modal?
Prior to raising the java modal, could you communicate back out to the page via liveconnect javascript call, setting a function to window.onclose that either sets focus back on the applet or prompts the user via browser confirm or alert?
Upon closing/dismissal of the applet dialog, you could clear the browser window.onclose function pointer.
Hope this helps,
-Scott H

Java applet/dialog strange behavior

I have a non-trivial Java applet. It has a menu, and via that menu applet shows a dialog that extends JDialog. Dialog is shown using setVisible(true). When user finishes working with that dialog, dialog is closed (after pressing "done" button) using this.dispose().
Now, there's a strange problem - applet works fine in Firefox, even in IE but in Chrome, when applet shows some other (dialog) window, that window is shown behind the applet. I have to click on the place where dialog should be in order to show it (bring it to front). If I click it again (while it's shown) it will disappear (go to background) again. Button clicks are working as usual, but whenever I click at popup window itself (even it's title-bar) it changes it's "visible" state.
Please, any idea what's wrong? How to resolve that bug?
// the applet will typically appear inside a Window, get a reference to it using:
Window parent = Window.getWindows()[0];
// use the window as the parent of a modal dialog.
JDialog dialog = new JDialog(parent);
dialog.setModal(true);
// ...
dialog.setVisible(true);
// won't be called until the applet is dismissed
someJComponent.requestFocusInWindow();
Applets embedded in web pages will always be subject to modality and focus problems. For a better user experience, launch the applet free-floating using Java Web Start, or even better still, launch a frame using JWS.

Categories

Resources