aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to make the only the Child form enabled? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make the only the Child form enabled?" Watch "How to make the only the Child form enabled?" New topic
Author

How to make the only the Child form enabled?

Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
My application is with JInterrnalFrames and JDesktopPane(Virtual desktop).
When I open up a child form, I would like to make parent form disabled.
I tried getting all InternalFrames in virtualdesktop and tried disabling it.I could get all internalframes but I could not disable them.
Any help?
Thanks
Sri
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi,
what do you mean with disabling a JInternalFrame.
Do you mean setEnabled(false)? I think, this can't work, because the components inside the frame are not disabled. You could try to work with the GlassPane. If you set the glasspane of your parent to visible, then no mouseclick would reach a component behind and the glasspane is the most top component. If your childframe is closed, then you have to set the glasspane to invisible.
Hope this helps a bit

Rene
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Rene
Currently I am opening my child Internal frame as below:

But , when my child internal frame is open, still my parent form is enabled and editable.
Thanks
Sri
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Yes, you are right, and I don't know why.
So you have to make a workaround. Put all your components in a Vector and implement a setAllComponentsEnabled(boolean enable) method.
This is ugly, but it will work. Maybe someone else knows, why the glasspane doesn't work.
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Is there a way to open the JInternal Frame as Modal. same as JDialog or JOptionPane
Thanks
Sri
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
No, not really. But it is possible, to simulate this. I did this two years ago.
Here is the code:

This is not modal, but it is alway on top.
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Rene
Thanks you very much for the code
I tried opening AlwaysOnTopInternalFrame class from my Partent Internal Frame and as desired I could not edit my Parent Form.
1) But when I clicked on the Parent form, AlwaysOnTopInternalFrame goes behind the Parent form
2) And When I close the AlwaysOnTopInternalFrame, my parent form is still non-editable.
Do I have to do anything different?
Thanks for your time Rene
Sri
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
I found it. My AlwaysOnTop.. worked, but the toFront() method of it was called earlier than the toFront method of the parent frame.
So I added following code to the parent frame:

In other words, I added a InternalFrameListener and in the implementation of it I ask if we have a child frame (which must be a member). If no then we have nothing to do and if yes, we send it to back.
But anyway, I think it will not solve your problem, because the parent frame is editable.
So I think you have to implement a recursive setComponentEnabled method for your internal frames. This you could merge with the AlwaysOnTopInternalFrame.

Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Rene
It looks like implementing setEnabledComponents() is the only option to disable and enable the Parent and Child Internalfrmaes though it does not seem sleek.
Now I am calling setEnabledComponents() right after my parent form open the child internalframe. But When I close my child form, how can I enable my parent form components.
Passing the parent form reference to the child form when the child form is open so that when the child form is closed I can use the parent for reference to call setEnabledComponents() method.
Thanks
Sri
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Ok, this is easy. As you already have a InternalFrameListener in your parent for your child, it is easy for you to listen for the internalFrameClosing event. There you can call the method setComponentEnabled(true).
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Rene
Thanks for your help.
I implemented the internalFrameClosing() on the Parent Frame and calling setComponentEnabled(true). But when my child form is closed, how the internalFrameClosing event on the Parent form will be fired. This event will be fired only when the parent form is closed. Am I missing something?
Sri
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Maybe my last post sounds a bit confusing. I mean, that your parent form has to implement a InternalFrameListener for the child form. Only then your parent is able to know when your child form is closing.

If this was a homework for you, then I shoud get your mark 1.
[ June 26, 2002: Message edited by: Rene Liebmann ]
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Thanks Rene. It worked
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to make the only the Child form enabled?