1 Replies - 4734 Views - Last Post: 02 January 2006 - 11:16 AM Rate Topic: -----

#1 laxmanrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-December 05

Improper behavior of exit button using a Enter Key

Posted 19 December 2005 - 11:22 PM

In my Swing application, while i am closing the window one popup(confirmation box) is coming.
JOptionPane.showConfirmDialog(dialog, "Do You really want to exit the application", "choose", JOptionPane.YES_NO_OPTION)

There appears an alert message like " Do You really want to exit the application" , Then move the cursor to "NO" and press " Enter " key with the keyboard

It is working fine for Mouse click but not working for EnterKey

Actual Result : It is closing the application

Expected Result : It should suspend the action

Any one can help on this.

Thanks
laxman

Is This A Good Question/Topic? 0
  • +

Replies To: Improper behavior of exit button using a Enter Key

#2 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Improper behavior of exit button using a Enter Key

Posted 02 January 2006 - 11:16 AM

I had a similar problem in my app. I had a YES/NO dialog and when I used the Tab key to move the focus to the No button and hit Enter, it would click the Yes button instead. I found out that it has to do with which button has the default focus. I believe the default focused button is different, depending on which L&F you are using. One way to make sure that the selected button follows the focus is to specify it at the beginning of your program with the following:
UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1