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.
Related
Why is it recommended to use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if there are ways to explicitly close the frame?
Calling setDefaultCloseOperation(EXIT_ON_CLOSE) causes the application to exit when the application receives a close window event from the operating system. Pressing the close (X) button on your window causes the operating system to generate a close window event and send it to your Java application. The close window event is processed by the AWT event loop in your Java application which will exit the application in response to the event. If you do not call this method the AWT event loop may not exit the application in response to the close window event but leave it running in the background.
JFrame.EXIT_ON_CLOSE stops the application from running in background. For example, if you didn't use JFrame.EXIT_ON_CLOSE, if your application has an active database connection, it will stay connected. To check this, you can open task manager and see the jar file still running even if its window is no longer visible.
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
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.
I have the main thread from which I start a window using invokeLater. I run my application from command line. So, when application is running I see the window and my command line is "blocked" by the application.
I can stop the application either by closing the window (as a result the command line is unblocked) or by typing Ctrl-C in the command line (as a result the window disappear).
I wanted to be able to stop the application by clicking on a button in the window of the application. I used setVisible(false) for that. But in this way I can achieve the goal only partially. My window really disappear but the command line is still blocked. So, the software is still running.
Well, I assume it's because some other threads are still running. But how can I easily close all these threads (like I do by closing the window of the application manually).
System.exit(0);
If it's a JFrame you're showing, you can tell it to exit the app when the frame is closed - the default is to just hide the frame:
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
This will exit the app if the user closes the window (top right [x] button often) , in addition you could have a Quit button whose event handler closes the window using myFrame.dispose();
You must finish all threads in order to stop your application. Just hiding the GUI will not finish the AWT-Thread. Have a look at the API of the GUI classes you use like the dispose-methods.
Try Window.dispose()
I have an application that runs in fullscreen mode and has been working fine. Now I need to add a simple, undecorated dialog and I'm running into trouble. If I run the application maximized but not in fullscreen, the dialog displays and functions as expected. When I switch back to fullscreen, the dialog will not display.
The dialog extends JDialog and only contains a JSlider and a couple of buttons. It is undecorated and not modal. (I disabled modality for testing purposes -- it was a pain to force exit the app every time the dialog blocked input.) I'm entering full screen mode using setFullScreenWindow(), passing in the main JFrame for the app. It doesn't make a difference if I set that very JFrame as the owner of the JDialog or not. Nor does it seem to help if I call toFront() on the dialog.
The dialog seems to be active -- especially since it blocks input if I make it modal -- but just not showing or being hidden. So, is there any obvious trick to displaying a JDialog in fullscreen mode? Something I might be overlooking or omitting?
If there's no obvious solution, I can post some code later. Unfortunately, I don't have time right now.
JOptionPane.showInternalXXXDialog()
methods render dialogs as JInternalFrames.
Maybe you could consider using a JIternaFrame to simulate the dialog box.
And in fact, as M1EK alluded in his answer and I mentioned in a comment, Java applications in full screen mode will not allow other windows to show over them. The Javadoc API for GraphicsDevice reads:
Windows cannot overlap the full-screen window. All other application windows will always appear beneath the full-screen window in the Z-order.
In the end, I reconfigured my application so that it doesn't enter full screen mode until a bit later. This still gives me a fairly class presentation at the start and allows my JDialog to function as it should. The transition to full screen mode is quick and smooth, even in the "middle" of my app.
Do you really want to be in full-screen mode for this app? That's more of a gaming feature - to get more direct access to the frame-buffer, I always thought. Have you read this tutorial:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html
Really seems to me not to be the best choice for a Swing app with child windows.
Try to use this. Is not an exclusive full screen but it is close enough.
setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);