I create a JWindow in my applet to display an update process, and I set the owner to the applet parent. My problem is that the JWindow is visible in all the tabs in my browser and not just the one containing my applet. Is it possible to add a Listener to know when my applet is visible? (And then hide the JWindow when it's not)
Asked
Active
Viewed 379 times
2 Answers
1
Applets appear to be added to a system Frame when they are displayed so you can use a WindowListener. I added the following code in the init() method of the JApplet:
Window window = SwingUtilities.windowForComponent(this);
window.addWindowListener( new WindowAdapter()
{
@Override
public void windowActivated(WindowEvent e)
{
displayWindow.setVisible( true );
}
@Override
public void windowDeactivated(WindowEvent e)
{
displayWindow.setVisible( false );
}
});

camickr
- 321,443
- 19
- 166
- 288
-
Thanks! It's working almost perfect. After I've switched back from another tab I have to click on the applet to activate it... – thomas.fogh Sep 13 '11 at 07:36
-
So then your original question has been solved and you should accept an answer. In the above example `window` refers to the window containing the applet. Maybe you can request focus on the Window in the windowActivated method. – camickr Sep 13 '11 at 14:34
-
And make a new "show jWindow when applet is visible"? ;) No point in requesting focus when windowActived is called, as the problem is that it's not called until the applet gets the focus... – thomas.fogh Sep 14 '11 at 11:17
0
I don't play much with applets but I think thats what the start()
and stop()
methods are for. You would make the window visible in start() and hide the window in stop().

camickr
- 321,443
- 19
- 166
- 288
-
as I understood correctly JWindow is still onFront(), even he's switched (for example FirefoxMozilla) to another browser's Tab – mKorbel Sep 12 '11 at 13:54
-
I just tried using the start/stop functions. They are not called when I change between tabs... – thomas.fogh Sep 12 '11 at 13:56
-
Hmm, I did a test using appletviewer. When I minimize/restore the frame the start/stop methods get invoked. However when I tried running the applet in IE and then minimizing/restore IE, nothing happend, so I guess I don't understand the purpose of these methds. – camickr Sep 13 '11 at 01:35