Java applet/dialog strange behavior - java

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.

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...

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

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

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.

JDialog Not Displaying When in Fullscreen Mode

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);

Categories

Resources