Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing parent and child with ESC

 
Pres Brawner
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presuming the child is modal, something like this:
 
Pres Brawner
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us what you have, and perhaps we can get an idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic