GeeCON Prague 2014*
The moose likes Java in General and the fly likes Closing parent and child with ESC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Closing parent and child with ESC" Watch "Closing parent and child with ESC" New topic
Author

Closing parent and child with ESC

Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
Hi all,
I have a dialog that will create a second dialog. When I hit the ESC key, I want to close the visible window. If only the parent is visible, I want to close the parent. If the child is visible, I only want to close the child. Right now, I'm closing both.
I'm just doing this:
protected void processKeyEvent(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
{
hide();
}
else
{
super.processKeyEvent(e);
}
}
any suggestions?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Presuming the child is modal, something like this:


"JavaRanch, where the deer and the Certified play" - David O'Meara
Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
A couple of questions:
What if it is not modal? How do I know for sure?
How do I determine the identify of "child"?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
If the child is modal, it will always be in front of the parent, and MUST be dealt with before doing anything to the parent. Actually the code that I gave you works in either case, however it will close the child dialog first, EVEN IF the parent dialog is currently in focus (in front of the child).
When you create the dialog you control the modal property either using the appropriate constructor or the setModal() method. By default it is non-modal, so if YOU didn't set it to modal then it's not.
Give the dialogs names:
Dialog parent = new Dialog();
Dialog child = new Dialog();
Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
OK. My child window is not modal.
The code you gave me does not work for me because I cannot identify "child".
I know I'm doing something wrong. I'm not thinking about this the way the designers of Swing intended. An "Ah Hah!" experience is near at hand. Could you give me another boost? I'm just not getting this yet.
Thanks,
Pres
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Show us what you have, and perhaps we can get an idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing parent and child with ESC