JApplet:  JFrames errors when returned to App

Hi,

Please excuse if this post should not appear under this topic. I’m doing some drawing on a panel in a JFrame that’s created from an applet. When a button is pressed on the applet a Window pops up and there are various components and drawings on that panel.

Everything works great when the page is first loaded. When I leave the page to go to say www.google.com then click the back button to return to the page, the JFrame no longer displays the components, draw anything or recognize any events sent to Swing components on this JFrame.

What is being done when I leave my page in IE to go to a different one then click back? What should I do or check to make sure my applet works correctly when I leave then return to the page?

Devyn

JFrame and JApplet are both top level containers, and heavyweights. In Swing you are not supposed to mix heavyweights with heavyweights. I’ve experienced erratic behavior when trying to mix the two as well. I even went so far to use a JPanel to re-implement an applet to use in a JFrame. Worked great :wink:

Maybe you should reconsider your design; why does your JApplet need a JFrame? JApplet has menubars etc so what is the advantage of adding using a JFrame? JApplet should only contain other lightweight components.

Mixing JApplets and JFrames does not cause a problem in Swing–at least I have never seen that or heard of that. (I could be wrong, but if I am, I’d be very interested and grateful to be enlighted with a relevant link or explanation.) The problems arise when one tries to add a heavyweight object to a lightweight object. Besides, JFrames are not added to the applet’s container tree anyway.

Also it is often useful to have JFrames in applets. For example you might want to allow the user to resize the UI. We do this pretty often where I work.

Hi all,

Well I got it to display the JFrames correctly now when the ‘Back’ button is pressed. All the panels are now repainted fine when I return to the page, but the JTextFields (Except for the first one clicked) no longer accept input or focus requests. All other components like radio buttons do.

When I click on the first JTextField it get’s the focus and the cursor, but the following JTextField no longer get’s any focus when clicked.

I noticed also that when I reinstantiate a single major JPanel I have on my applet, everything works fine and I can press back as many times as I like and there are no problems. I might stay with that but I would like to maintain as much of the applet current state as I can when the user returns to it.

I’m starting to think that it’s probaby an event queue problem, or something to do with listeners added to components. Since I have no idea what IE does to an applet when a user leaves a page, it’s hard to tell.

Devyn

BTW, I’m not adding JFrames to the JApplet. I’m creating new windows using JFrames from within panels that have been added to the JApplet.