aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Strange problem on JDialog show method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Strange problem on JDialog show method" Watch "Strange problem on JDialog show method" New topic
Author

Strange problem on JDialog show method

David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, there:

I met a strange problem on JDialog. I have a swing application, using JDK1.3, eclipse 2.1.3 as my developing tool. I have a dialog extends from JDialog, which is supposed to pop up for "yes" and "no" choice. Everything works fine if I invoke the application from "debug" mode. However, if I invoke the application from "run" mode, everything works fine too if I use mouse clicking, but if I just use keyboard input, the dialog works fine first time, after the first time pop up, the dialog seems accept the "Enter" key automatically somewhere, so that the dialog closed immediately after "show" method is called, before I got a chance to press any key. And the dialog always selects "yes" automatically.

Really appreciated if anyone has any clue.

Thanks a lot in advance
David Chen
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, there:

The problem seems that a keyevent was not consumed by the other GUI component. In my swing application, I have a combobox, by using keyboard only, after I choose an item in combobox and press "Enter" key, the dialog is supposed to be popped up with "Yes" and "No" choice.
The problem seems like that:
1. the combobox has keyPressed() defined (with keyReleased() empty);
2. the following dialog class has keyReleased() defined (with keyPressed() empty);
3. So, after press "Enter" key in combobox, KEY_PRESSED event is consumed by combobox in its keyPressed() but KEY_RELEASED event is not consumed for some reasons I don't know, which causes the problem that the dialog's method keyReleased() is trigged automatically by that event. And, after I move those logic in dialog class from keyReleased() to keyPressed() everything works fine.
However, I'm still not very sure why that KEY_RELEASED event is not consumed by the combobox (I did define an empty keyReleased() method in combobox)? Or it may come from other reason?

Really appreciated if anyone can clarify me on that issue.

Thanks a lot
David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange problem on JDialog show method